aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraaronbuchwald <aaron.buchwald56@gmail.com>2020-09-17 09:36:44 -0400
committerGitHub <noreply@github.com>2020-09-17 09:36:44 -0400
commit42ee77a946d062a4c8e1fabc394ac016ae30e68e (patch)
tree85da01f5b75788e257d3c355917a4b3a8ad8603b
parent92fdc0a4b6208387424029182a131b25a2f92dac (diff)
parent6b4efa7ff5537a7cdb1d73b18dd75f56bdadc032 (diff)
Merge pull request #33 from ava-labs/fix-nil-pointer
Fix potential nil pointer dereference
-rw-r--r--core/blockchain.go17
-rw-r--r--core/state/statedb.go9
-rw-r--r--core/types/block.go3
-rw-r--r--coreth.go5
-rw-r--r--examples/multicoin/main.go3
-rw-r--r--miner/miner.go4
-rw-r--r--plugin/evm/vm.go28
-rw-r--r--rpc/types.go7
8 files changed, 53 insertions, 23 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
}
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
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
}
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/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/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 2b78d43..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"
@@ -160,7 +161,7 @@ type VM struct {
chaindb Database
newBlockChan chan *Block
networkChan chan<- commonEng.Message
- newTxPoolHeadChan chan core.NewTxPoolHeadEvent
+ newTxPoolHeadChan *event.TypeMuxSubscription
acceptedDB database.Database
@@ -244,6 +245,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
@@ -340,23 +345,28 @@ 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.(type) {
+ case core.NewMinedBlockEvent:
+ vm.txPoolStabilizedLock.Lock()
+ if vm.txPoolStabilizedHead == h.Block.Hash() {
+ vm.txPoolStabilizedOk <- struct{}{}
+ vm.txPoolStabilizedHead = common.Hash{}
+ }
+ vm.txPoolStabilizedLock.Unlock()
+ default:
}
- vm.txPoolStabilizedLock.Unlock()
}
}
})
diff --git a/rpc/types.go b/rpc/types.go
index 6575203..3ee46f3 100644
--- a/rpc/types.go
+++ b/rpc/types.go
@@ -148,13 +148,18 @@ 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":
bn := PendingBlockNumber
bnh.BlockNumber = &bn
return nil
+ case "accepted":
+ bn := AcceptedBlockNumber
+ bnh.BlockNumber = &bn
+ return nil
default:
if len(input) == 66 {
hash := common.Hash{}