diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/block_validator.go | 6 | ||||
-rw-r--r-- | core/blockchain.go | 7 | ||||
-rw-r--r-- | core/state_transition.go | 7 | ||||
-rw-r--r-- | core/types/transaction.go | 1 | ||||
-rw-r--r-- | core/vm/environment.go | 2 |
5 files changed, 14 insertions, 9 deletions
diff --git a/core/block_validator.go b/core/block_validator.go index f777b9f23..c3f959324 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -64,7 +64,7 @@ func NewBlockValidator(config *ChainConfig, blockchain *BlockChain, pow pow.PoW) // // ValidateBlock also validates and makes sure that any previous state (or present) // state that might or might not be present is checked to make sure that fast -// sync has done it's job proper. This prevents the block validator form accepting +// sync has done it's job proper. This prevents the block validator from accepting // false positives where a header is present but the state is not. func (v *BlockValidator) ValidateBlock(block *types.Block) error { if v.bc.HasBlock(block.Hash()) { @@ -139,7 +139,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat // error if any of the included uncle headers were invalid. It returns an error // if the validation failed. func (v *BlockValidator) VerifyUncles(block, parent *types.Block) error { - // validate that there at most 2 uncles included in this block + // validate that there are at most 2 uncles included in this block if len(block.Uncles()) > 2 { return ValidationError("Block can only contain maximum 2 uncles (contained %v)", len(block.Uncles())) } @@ -193,7 +193,7 @@ func (v *BlockValidator) ValidateHeader(header, parent *types.Header, checkPow b if parent == nil { return ParentError(header.ParentHash) } - // Short circuit if the header's already known or its parent missing + // Short circuit if the header's already known or its parent is missing if v.bc.HasHeader(header.Hash()) { return nil } diff --git a/core/blockchain.go b/core/blockchain.go index 95bada5ee..950804d40 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -771,14 +771,13 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err if ptd == nil { return NonStatTy, ParentError(block.ParentHash()) } - - localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64()) - externTd := new(big.Int).Add(block.Difficulty(), ptd) - // Make sure no inconsistent state is leaked during insertion self.mu.Lock() defer self.mu.Unlock() + localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64()) + externTd := new(big.Int).Add(block.Difficulty(), ptd) + // If the total difficulty is higher than our known, add it to the canonical chain // Second clause in the if statement reduces the vulnerability to selfish mining. // Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf diff --git a/core/state_transition.go b/core/state_transition.go index c8160424b..9e6b2f567 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -71,6 +71,7 @@ type Message interface { Value() *big.Int Nonce() uint64 + CheckNonce() bool Data() []byte } @@ -208,8 +209,10 @@ func (self *StateTransition) preCheck() (err error) { } // Make sure this transaction's nonce is correct - if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() { - return NonceError(msg.Nonce(), n) + if msg.CheckNonce() { + if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() { + return NonceError(msg.Nonce(), n) + } } // Pre-pay gas diff --git a/core/types/transaction.go b/core/types/transaction.go index b99d3a716..c71c98aa7 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -113,6 +113,7 @@ func (tx *Transaction) Gas() *big.Int { return new(big.Int).Set(tx.data.Gas func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) } func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) } func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce } +func (tx *Transaction) CheckNonce() bool { return true } func (tx *Transaction) To() *common.Address { if tx.data.Recipient == nil { diff --git a/core/vm/environment.go b/core/vm/environment.go index 747627565..664887454 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -73,6 +73,8 @@ type Environment interface { DelegateCall(me ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error) // Create a new contract Create(me ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) + + StructLogs() []StructLog } // Vm is the basic interface for an implementation of the EVM. |