aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-09-18 13:09:22 -0400
committerDeterminant <[email protected]>2020-09-18 13:09:22 -0400
commit3ea6a7940e40677b629270dfc7a1466bca295bd3 (patch)
tree1a7f65fcd72e77092525ab01625b8b9d365e3e40
parentb0a75c03303fe22f31fe1e1f0fa29a1e1cd78253 (diff)
clean up the code
-rw-r--r--consensus/dummy/consensus.go4
-rw-r--r--core/types/block.go26
-rw-r--r--examples/block/main.go2
-rw-r--r--examples/counter/main.go2
-rw-r--r--examples/payments/main.go2
-rw-r--r--plugin/evm/database.go10
-rw-r--r--plugin/evm/vm.go22
-rw-r--r--rpc/types.go2
8 files changed, 30 insertions, 40 deletions
diff --git a/consensus/dummy/consensus.go b/consensus/dummy/consensus.go
index 42e224d..da63673 100644
--- a/consensus/dummy/consensus.go
+++ b/consensus/dummy/consensus.go
@@ -262,10 +262,10 @@ func (self *DummyEngine) Finalize(
func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
- var extdata *[]byte
+ var extdata []byte
if self.cb.OnFinalizeAndAssemble != nil {
ret, err := self.cb.OnFinalizeAndAssemble(state, txs)
- extdata = &ret
+ extdata = ret
if err != nil {
return nil, err
}
diff --git a/core/types/block.go b/core/types/block.go
index 0a93601..8e23488 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -235,7 +235,7 @@ type storageblock struct {
// The values of TxHash, UncleHash, ReceiptHash and Bloom in header
// are ignored and set to values derived from the given txs, uncles
// and receipts.
-func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata *[]byte) *Block {
+func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata []byte) *Block {
b := &Block{header: CopyHeader(header), td: new(big.Int)}
// TODO: panic if len(txs) != len(receipts)
@@ -265,9 +265,9 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*
}
if extdata != nil {
- data := make([]byte, len(*extdata))
- b.extdata = &data
- copy(*b.extdata, *extdata)
+ _data := make([]byte, len(extdata))
+ b.extdata = &_data
+ copy(*b.extdata, extdata)
}
return b
@@ -324,7 +324,13 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error {
}
func (b *Block) SetExtraData(data []byte) {
- b.extdata = &data
+ if data != nil {
+ _data := make([]byte, len(data))
+ b.extdata = &_data
+ copy(*b.extdata, data)
+ } else {
+ b.extdata = nil
+ }
b.header.ExtDataHash = rlpHash(data)
b.hash = atomic.Value{}
}
@@ -467,22 +473,20 @@ func (b *Block) WithSeal(header *Header) *Block {
// WithBody returns a new block with the given transaction and uncle contents.
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata *[]byte) *Block {
- var data *[]byte
+ var extdataCopied *[]byte
if extdata != nil {
_data := make([]byte, len(*extdata))
- data = &_data
+ extdataCopied = &_data
+ copy(*extdataCopied, *extdata)
}
block := &Block{
header: CopyHeader(b.header),
transactions: make([]*Transaction, len(transactions)),
uncles: make([]*Header, len(uncles)),
- extdata: data,
+ extdata: extdataCopied,
version: version,
}
copy(block.transactions, transactions)
- if data != nil {
- copy(*block.extdata, *extdata)
- }
for i := range uncles {
block.uncles[i] = CopyHeader(uncles[i])
}
diff --git a/examples/block/main.go b/examples/block/main.go
index 89540c6..55fedfe 100644
--- a/examples/block/main.go
+++ b/examples/block/main.go
@@ -37,7 +37,7 @@ func main() {
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
- IstanbulBlock: nil,
+ IstanbulBlock: big.NewInt(0),
Ethash: nil,
}
diff --git a/examples/counter/main.go b/examples/counter/main.go
index 9e18cd8..f78f28f 100644
--- a/examples/counter/main.go
+++ b/examples/counter/main.go
@@ -45,7 +45,7 @@ func main() {
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
- IstanbulBlock: nil,
+ IstanbulBlock: big.NewInt(0),
Ethash: nil,
}
diff --git a/examples/payments/main.go b/examples/payments/main.go
index fee2060..9023b3a 100644
--- a/examples/payments/main.go
+++ b/examples/payments/main.go
@@ -36,7 +36,7 @@ func main() {
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
- IstanbulBlock: nil,
+ IstanbulBlock: big.NewInt(0),
Ethash: nil,
}
diff --git a/plugin/evm/database.go b/plugin/evm/database.go
index 81d1c1d..18890fa 100644
--- a/plugin/evm/database.go
+++ b/plugin/evm/database.go
@@ -46,16 +46,6 @@ func (db Database) Sync() error { return errOpNotSupported }
// NewBatch implements ethdb.Database
func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} }
-//// NewIterator implements ethdb.Database
-//func (db Database) NewIterator() ethdb.Iterator {
-// return db.Database.NewIterator()
-//}
-
-//// NewIteratorWithPrefix implements ethdb.Database
-//func (db Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
-// return db.NewIteratorWithPrefix(prefix)
-//}
-
// NewIterator implements ethdb.Database
func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
return db.NewIteratorWithStartAndPrefix(start, prefix)
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index c02b835..200a08d 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -154,14 +154,14 @@ func init() {
type VM struct {
ctx *snow.Context
- chainID *big.Int
- networkID uint64
- genesisHash common.Hash
- chain *coreth.ETHChain
- chaindb Database
- newBlockChan chan *Block
- networkChan chan<- commonEng.Message
- newTxPoolHeadChan *event.TypeMuxSubscription
+ chainID *big.Int
+ networkID uint64
+ genesisHash common.Hash
+ chain *coreth.ETHChain
+ chaindb Database
+ newBlockChan chan *Block
+ networkChan chan<- commonEng.Message
+ newMinedBlockSub *event.TypeMuxSubscription
acceptedDB database.Database
@@ -349,15 +349,13 @@ func (vm *VM) Initialize(
vm.bdTimerState = bdTimerStateLong
vm.bdGenWaitFlag = true
- //vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1)
vm.txPoolStabilizedOk = make(chan struct{}, 1)
vm.txPoolStabilizedShutdownChan = make(chan struct{}, 1) // Signal goroutine to shutdown
// TODO: read size from options
vm.pendingAtomicTxs = make(chan *Tx, 1024)
vm.atomicTxSubmitChan = make(chan struct{}, 1)
vm.shutdownSubmitChan = make(chan struct{}, 1)
- //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan)
- vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent()
+ vm.newMinedBlockSub = vm.chain.SubscribeNewMinedBlockEvent()
vm.shutdownWg.Add(1)
go ctx.Log.RecoverAndPanic(vm.awaitTxPoolStabilized)
chain.Start()
@@ -733,7 +731,7 @@ func (vm *VM) awaitTxPoolStabilized() {
defer vm.shutdownWg.Done()
for {
select {
- case e := <-vm.newTxPoolHeadChan.Chan():
+ case e := <-vm.newMinedBlockSub.Chan():
switch h := e.Data.(type) {
case core.NewMinedBlockEvent:
vm.txPoolStabilizedLock.Lock()
diff --git a/rpc/types.go b/rpc/types.go
index 3ee46f3..99e29fc 100644
--- a/rpc/types.go
+++ b/rpc/types.go
@@ -92,7 +92,6 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
*bn = EarliestBlockNumber
return nil
case "latest":
- //*bn = LatestBlockNumber
*bn = AcceptedBlockNumber
return nil
case "pending":
@@ -148,7 +147,6 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bnh.BlockNumber = &bn
return nil
case "latest":
- //*bn = LatestBlockNumber
bn := AcceptedBlockNumber
bnh.BlockNumber = &bn
return nil