From 13ebd8bd9468e9d769d598b0ca2afb72ba78cb97 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 28 Jun 2020 01:00:40 -0400 Subject: use non-zero hash as the blackhole --- coreth.go | 6 +++--- plugin/evm/vm.go | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/coreth.go b/coreth.go index f7e89ef..b7e45af 100644 --- a/coreth.go +++ b/coreth.go @@ -23,8 +23,8 @@ import ( ) var ( - ZeroAddr = common.Address{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + BlackholeAddr = common.Address{ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } ) @@ -66,7 +66,7 @@ func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Add backend, _ := eth.New(&ctx, config, cb, mcb, bcb, chainDB) chain := ÐChain{backend: backend, cb: cb, mcb: mcb, bcb: bcb} if etherBase == nil { - etherBase = &ZeroAddr + etherBase = &BlackholeAddr } backend.SetEtherbase(*etherBase) return chain diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index db1f5a9..4b16f71 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -39,11 +39,10 @@ import ( ) var ( - oldZeroAddr = common.Address{ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + zeroAddr = common.Address{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } - zeroAddr = coreth.ZeroAddr ) const ( @@ -84,6 +83,7 @@ type VM struct { chainID *big.Int networkID uint64 + genesisHash common.Hash chain *coreth.ETHChain chaindb Database newBlockChan chan *Block @@ -146,7 +146,7 @@ func (vm *VM) Initialize( panic(err) } nodecfg := node.Config{NoUSB: true} - chain := coreth.NewETHChain(&config, &nodecfg, &zeroAddr, vm.chaindb) + chain := coreth.NewETHChain(&config, &nodecfg, nil, vm.chaindb) vm.chain = chain vm.networkID = config.NetworkId chain.SetOnHeaderNew(func(header *types.Header) { @@ -245,6 +245,7 @@ func (vm *VM) Initialize( ethBlock: lastAccepted, vm: vm, } + vm.genesisHash = chain.GetGenesisBlock().Hash() vm.ctx.Log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) // TODO: shutdown this go routine @@ -313,14 +314,14 @@ func (vm *VM) ParseBlock(b []byte) (snowman.Block, error) { if err := rlp.DecodeBytes(b, ethBlock); err != nil { return nil, err } + blockHash := ethBlock.Hash() // Coinbase must be zero on C-Chain - coinbase := ethBlock.Coinbase() - if bytes.Compare(coinbase.Bytes(), oldZeroAddr.Bytes()) != 0 && - bytes.Compare(coinbase.Bytes(), zeroAddr.Bytes()) != 0 { + if bytes.Compare(blockHash.Bytes(), vm.genesisHash.Bytes()) != 0 && + bytes.Compare(ethBlock.Coinbase().Bytes(), coreth.BlackholeAddr.Bytes()) != 0 { return nil, errInvalidBlock } block := &Block{ - id: ids.NewID(ethBlock.Hash()), + id: ids.NewID(blockHash), ethBlock: ethBlock, vm: vm, } -- cgit v1.2.3-70-g09d2