From: Chengcheng Zhang <943420582@qq.com> Date: Thu, 6 Jun 2019 08:26:25 +0000 (+0800) Subject: find whether config xpubs equal genesis block xpubs (#142) X-Git-Tag: v1.0.5~208^2~58 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=aa87732ffe2e2418d8f1ae37da388ecf73e59621 find whether config xpubs equal genesis block xpubs (#142) * find whether config xpubs equal genesis block xpubs * update --- diff --git a/node/node.go b/node/node.go index 3dc31904..61f26b16 100644 --- a/node/node.go +++ b/node/node.go @@ -9,6 +9,7 @@ import ( _ "net/http/pprof" "os" "path/filepath" + "reflect" "github.com/prometheus/prometheus/util/flock" log "github.com/sirupsen/logrus" @@ -31,6 +32,7 @@ import ( "github.com/vapor/netsync" "github.com/vapor/proposal/blockproposer" "github.com/vapor/protocol" + "github.com/vapor/protocol/bc/types" w "github.com/vapor/wallet" ) @@ -98,6 +100,10 @@ func NewNode(config *cfg.Config) *Node { cmn.Exit(cmn.Fmt("Failed to create chain structure: %v", err)) } + if err := checkConfig(chain, config); err != nil { + panic(err) + } + var accounts *account.Manager var assets *asset.Registry var wallet *w.Wallet @@ -168,6 +174,22 @@ func NewNode(config *cfg.Config) *Node { return node } +// find whether config xpubs equal genesis block xpubs +func checkConfig(chain *protocol.Chain, config *cfg.Config) error { + fedpegScript := cfg.FederationProgrom(config) + genesisBlock, err := chain.GetBlockByHeight(0) + if err != nil { + return err + } + typedInput := genesisBlock.Transactions[0].Inputs[0].TypedInput + if v, ok := typedInput.(*types.CoinbaseInput); ok { + if !reflect.DeepEqual(fedpegScript, v.Arbitrary) { + return errors.New("config xpubs don't equal genesis block xpubs.") + } + } + return nil +} + // Lock data directory after daemonization func lockDataDirectory(config *cfg.Config) error { _, _, err := flock.New(filepath.Join(config.RootDir, "LOCK"))