OSDN Git Service

find whether config xpubs equal genesis block xpubs (#142)
authorChengcheng Zhang <943420582@qq.com>
Thu, 6 Jun 2019 08:26:25 +0000 (16:26 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 6 Jun 2019 08:26:25 +0000 (16:26 +0800)
* find whether config xpubs equal genesis block xpubs

* update

node/node.go

index 3dc3190..61f26b1 100644 (file)
@@ -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"))