From 3ddf58c70d33f85c9d3521f34e4c3fba0deca1e3 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 16 Sep 2020 23:46:18 -0400 Subject: add the missing IsMultiCoin assignment --- core/state/statedb.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index b472bd7..81be542 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -579,10 +579,11 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { return nil } data = &Account{ - Nonce: acc.Nonce, - Balance: acc.Balance, - CodeHash: acc.CodeHash, - Root: common.BytesToHash(acc.Root), + Nonce: acc.Nonce, + Balance: acc.Balance, + CodeHash: acc.CodeHash, + IsMultiCoin: acc.IsMultiCoin, + Root: common.BytesToHash(acc.Root), } if len(data.CodeHash) == 0 { data.CodeHash = emptyCodeHash -- cgit v1.2.3 From 7063564c571bcdc94b981db7ed3707902f0466d0 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 00:25:32 -0400 Subject: disable snapshot --- examples/multicoin/main.go | 3 +++ plugin/evm/vm.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/examples/multicoin/main.go b/examples/multicoin/main.go index fc379d4..bfad5ca 100644 --- a/examples/multicoin/main.go +++ b/examples/multicoin/main.go @@ -64,6 +64,9 @@ func main() { genKey := coreth.NewKeyFromECDSA(hk) config.Genesis = genesisBlock + config.TrieCleanCache += config.SnapshotCache + config.SnapshotCache = 0 + // grab the control of block generation and disable auto uncle config.Miner.ManualMining = true config.Miner.ManualUncle = true diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 993727e..55411cf 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -243,6 +243,10 @@ func (vm *VM) Initialize( config := eth.DefaultConfig config.ManualCanonical = true config.Genesis = g + // disable the experimental snapshot feature from geth + config.TrieCleanCache += config.SnapshotCache + config.SnapshotCache = 0 + config.Miner.ManualMining = true config.Miner.DisableUncle = true -- cgit v1.2.3 From 160a8f543b3a2e9ed38f806015e4f1f0d1f49f8d Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 01:36:24 -0400 Subject: revert the SetTail logic --- core/blockchain.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index b3a7ffa..82e3b6c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2492,13 +2492,12 @@ func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscr } func (bc *BlockChain) ManualHead(hash common.Hash) error { - return bc.FastSyncCommitHead(hash) - //block := bc.GetBlockByHash(hash) - //if block == nil { - // return errors.New("block not found") - //} - //bc.chainmu.Lock() - //defer bc.chainmu.Unlock() - //bc.writeHeadBlock(block) - //return nil + block := bc.GetBlockByHash(hash) + if block == nil { + return errors.New("block not found") + } + bc.chainmu.Lock() + defer bc.chainmu.Unlock() + bc.writeHeadBlock(block) + return nil } -- cgit v1.2.3 From 5d5c982b90375cc1ff3133566091e1fbac2b0b67 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 02:04:21 -0400 Subject: ... --- rpc/types.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rpc/types.go b/rpc/types.go index 6575203..e46532c 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -155,6 +155,10 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { bn := PendingBlockNumber bnh.BlockNumber = &bn return nil + case "accepted": + bn := AcceptedBlockNumber + bnh.BlockNumber = &bn + return nil default: if len(input) == 66 { hash := common.Hash{} -- cgit v1.2.3 From 3b7ebac681f551a9f9931e9d68de402d4cff8c0d Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 02:07:45 -0400 Subject: ... --- rpc/types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/types.go b/rpc/types.go index e46532c..3ee46f3 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -148,7 +148,8 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { bnh.BlockNumber = &bn return nil case "latest": - bn := LatestBlockNumber + //*bn = LatestBlockNumber + bn := AcceptedBlockNumber bnh.BlockNumber = &bn return nil case "pending": -- cgit v1.2.3 From aedd4b46cdc0a48c1b06a3e920bf57f8c28d401d Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 03:08:39 -0400 Subject: fix the block completion race --- coreth.go | 5 +++++ miner/miner.go | 4 ++++ plugin/evm/vm.go | 21 ++++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/coreth.go b/coreth.go index 4d0c2ee..1d6b92e 100644 --- a/coreth.go +++ b/coreth.go @@ -17,6 +17,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/trie" //"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" @@ -85,6 +86,10 @@ func (self *ETHChain) GenBlock() { self.backend.Miner().GenBlock() } +func (self *ETHChain) SubscribeNewMinedBlockEvent() *event.TypeMuxSubscription { + return self.backend.Miner().GetWorkerMux().Subscribe(core.NewMinedBlockEvent{}) +} + func (self *ETHChain) VerifyBlock(block *types.Block) bool { txnHash := types.DeriveSha(block.Transactions(), new(trie.Trie)) uncleHash := types.CalcUncleHash(block.Uncles()) diff --git a/miner/miner.go b/miner/miner.go index e8e59a4..bbe704f 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -135,3 +135,7 @@ func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscript func (miner *Miner) GenBlock() { miner.worker.genBlock() } + +func (miner *Miner) GetWorkerMux() *event.TypeMux { + return miner.worker.mux +} diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c6bc728..c9836c6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -160,7 +160,7 @@ type VM struct { chaindb Database newBlockChan chan *Block networkChan chan<- commonEng.Message - newTxPoolHeadChan chan core.NewTxPoolHeadEvent + newTxPoolHeadChan *event.TypeMuxSubscription acceptedDB database.Database @@ -344,23 +344,26 @@ func (vm *VM) Initialize( vm.bdTimerState = bdTimerStateLong vm.bdGenWaitFlag = true - vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) + //vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) vm.txPoolStabilizedOk = make(chan struct{}, 1) // TODO: read size from options vm.pendingAtomicTxs = make(chan *Tx, 1024) vm.atomicTxSubmitChan = make(chan struct{}, 1) - chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) + //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) + vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent() // TODO: shutdown this go routine go ctx.Log.RecoverAndPanic(func() { for { select { - case h := <-vm.newTxPoolHeadChan: - vm.txPoolStabilizedLock.Lock() - if vm.txPoolStabilizedHead == h.Block.Hash() { - vm.txPoolStabilizedOk <- struct{}{} - vm.txPoolStabilizedHead = common.Hash{} + case e := <-vm.newTxPoolHeadChan.Chan(): + switch h := e.Data.(core.NewTxPoolHeadEvent) { + vm.txPoolStabilizedLock.Lock() + if vm.txPoolStabilizedHead == h.Block.Hash() { + vm.txPoolStabilizedOk <- struct{}{} + vm.txPoolStabilizedHead = common.Hash{} + } + vm.txPoolStabilizedLock.Unlock() } - vm.txPoolStabilizedLock.Unlock() } } }) -- cgit v1.2.3 From 8123ec9caeb1917519c1f8f67f386df142578728 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 03:23:13 -0400 Subject: ... --- plugin/evm/vm.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c9836c6..73a97e8 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" @@ -356,13 +357,15 @@ func (vm *VM) Initialize( for { select { case e := <-vm.newTxPoolHeadChan.Chan(): - switch h := e.Data.(core.NewTxPoolHeadEvent) { + switch h := e.Data.(type) { + case core.NewMinedBlockEvent: vm.txPoolStabilizedLock.Lock() if vm.txPoolStabilizedHead == h.Block.Hash() { vm.txPoolStabilizedOk <- struct{}{} vm.txPoolStabilizedHead = common.Hash{} } vm.txPoolStabilizedLock.Unlock() + default: } } } -- cgit v1.2.3 From 6b4efa7ff5537a7cdb1d73b18dd75f56bdadc032 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 17 Sep 2020 09:20:36 -0400 Subject: Fix potential nil pointer dereference --- core/types/block.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/types/block.go b/core/types/block.go index 99d6cc8..0a93601 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -330,6 +330,9 @@ func (b *Block) SetExtraData(data []byte) { } func (b *Block) ExtraData() []byte { + if b.extdata == nil { + return nil + } return *b.extdata } -- cgit v1.2.3