forked from cerc-io/plugeth
consensus, core, core/vm, parems: review fixes
This commit is contained in:
parent
e6aff513db
commit
a5f6a1cb7c
@ -315,7 +315,7 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
|
|||||||
// (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
// (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
|
||||||
// ) + 2^(periodCount - 2)
|
// ) + 2^(periodCount - 2)
|
||||||
|
|
||||||
bigTime := new(big.Int).Set(time)
|
bigTime := new(big.Int).SetUint64(time)
|
||||||
bigParentTime := new(big.Int).Set(parent.Time)
|
bigParentTime := new(big.Int).Set(parent.Time)
|
||||||
|
|
||||||
// holds intermediate values to make the algo easier to read & audit
|
// holds intermediate values to make the algo easier to read & audit
|
||||||
|
@ -209,9 +209,6 @@ func makeHeader(config *params.ChainConfig, parent *types.Block, state *state.St
|
|||||||
} else {
|
} else {
|
||||||
time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
|
time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
|
||||||
}
|
}
|
||||||
parentHeader := parent.Header()
|
|
||||||
// adjust the parent time
|
|
||||||
parentHeader.Time = new(big.Int).Sub(time, big.NewInt(10))
|
|
||||||
|
|
||||||
return &types.Header{
|
return &types.Header{
|
||||||
Root: state.IntermediateRoot(config.IsEIP158(parent.Number())),
|
Root: state.IntermediateRoot(config.IsEIP158(parent.Number())),
|
||||||
|
@ -108,17 +108,6 @@ type Signer interface {
|
|||||||
Equal(Signer) bool
|
Equal(Signer) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// WithSignature returns a new transaction with the given signature. This signature
|
|
||||||
// needs to be in the [R || S || V] format where V is 0 or 1.
|
|
||||||
func (s EIP86Signer) WithSignature(tx *Transaction, sig []byte) (*Transaction, error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash returns the hash to be signed by the sender.
|
|
||||||
// It does not uniquely identify the transaction.
|
|
||||||
func (s EIP86Signer) Hash(tx *Transaction) common.Hash {}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// EIP155Transaction implements TransactionInterface using the
|
// EIP155Transaction implements TransactionInterface using the
|
||||||
// EIP155 rules
|
// EIP155 rules
|
||||||
type EIP155Signer struct {
|
type EIP155Signer struct {
|
||||||
|
@ -45,7 +45,7 @@ type Config struct {
|
|||||||
DisableGasMetering bool
|
DisableGasMetering bool
|
||||||
// Enable recording of SHA3/keccak preimages
|
// Enable recording of SHA3/keccak preimages
|
||||||
EnablePreimageRecording bool
|
EnablePreimageRecording bool
|
||||||
// JumpTable contains the in instruction table. This
|
// JumpTable contains the EVM instruction table. This
|
||||||
// may me left uninitialised and will be set the default
|
// may me left uninitialised and will be set the default
|
||||||
// table.
|
// table.
|
||||||
JumpTable [256]operation
|
JumpTable [256]operation
|
||||||
@ -74,7 +74,7 @@ func NewInterpreter(evm *EVM, cfg Config) *Interpreter {
|
|||||||
case evm.ChainConfig().IsHomestead(evm.BlockNumber):
|
case evm.ChainConfig().IsHomestead(evm.BlockNumber):
|
||||||
cfg.JumpTable = homesteadInstructionSet
|
cfg.JumpTable = homesteadInstructionSet
|
||||||
default:
|
default:
|
||||||
cfg.JumpTable = baseInstructionSet
|
cfg.JumpTable = frontierInstructionSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,14 +131,14 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Debug("in running contract", "hash", codehash[:])
|
log.Debug("interpreter running contract", "hash", codehash[:])
|
||||||
tstart := time.Now()
|
tstart := time.Now()
|
||||||
defer log.Debug("in finished running contract", "hash", codehash[:], "elapsed", time.Since(tstart))
|
defer log.Debug("interpreter finished running contract", "hash", codehash[:], "elapsed", time.Since(tstart))
|
||||||
|
|
||||||
// The Interpreter main run loop (contextual). This loop runs until either an
|
// The Interpreter main run loop (contextual). This loop runs until either an
|
||||||
// explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during
|
// explicit STOP, RETURN or SELFDESTRUCT is executed, an error occurred during
|
||||||
// the execution of one of the operations or until the in.done is set by
|
// the execution of one of the operations or until the done flag is set by the
|
||||||
// the parent context.Context.
|
// parent context.
|
||||||
for atomic.LoadInt32(&in.evm.abort) == 0 {
|
for atomic.LoadInt32(&in.evm.abort) == 0 {
|
||||||
// Get the memory location of pc
|
// Get the memory location of pc
|
||||||
op = contract.GetOp(pc)
|
op = contract.GetOp(pc)
|
||||||
|
@ -56,12 +56,14 @@ type operation struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
baseInstructionSet = NewBaseInstructionSet()
|
frontierInstructionSet = NewFrontierInstructionSet()
|
||||||
homesteadInstructionSet = NewHomesteadInstructionSet()
|
homesteadInstructionSet = NewHomesteadInstructionSet()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewHomesteadInstructionSet returns the frontier and homestead
|
||||||
|
// instructions that can be executed during the homestead phase.
|
||||||
func NewHomesteadInstructionSet() [256]operation {
|
func NewHomesteadInstructionSet() [256]operation {
|
||||||
instructionSet := NewBaseInstructionSet()
|
instructionSet := NewFrontierInstructionSet()
|
||||||
instructionSet[DELEGATECALL] = operation{
|
instructionSet[DELEGATECALL] = operation{
|
||||||
execute: opDelegateCall,
|
execute: opDelegateCall,
|
||||||
gasCost: gasDelegateCall,
|
gasCost: gasDelegateCall,
|
||||||
@ -72,7 +74,9 @@ func NewHomesteadInstructionSet() [256]operation {
|
|||||||
return instructionSet
|
return instructionSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseInstructionSet() [256]operation {
|
// NewFrontierInstructionSet returns the frontier instructions
|
||||||
|
// that can be executed during the frontier phase.
|
||||||
|
func NewFrontierInstructionSet() [256]operation {
|
||||||
return [256]operation{
|
return [256]operation{
|
||||||
STOP: {
|
STOP: {
|
||||||
execute: opStop,
|
execute: opStop,
|
||||||
|
@ -56,14 +56,16 @@ var (
|
|||||||
|
|
||||||
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
|
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
|
||||||
RinkebyChainConfig = &ChainConfig{
|
RinkebyChainConfig = &ChainConfig{
|
||||||
ChainId: big.NewInt(4),
|
ChainId: big.NewInt(4),
|
||||||
HomesteadBlock: big.NewInt(1),
|
HomesteadBlock: big.NewInt(1),
|
||||||
DAOForkBlock: nil,
|
DAOForkBlock: nil,
|
||||||
DAOForkSupport: true,
|
DAOForkSupport: true,
|
||||||
EIP150Block: big.NewInt(2),
|
EIP150Block: big.NewInt(2),
|
||||||
EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
|
EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
|
||||||
EIP155Block: big.NewInt(3),
|
EIP155Block: big.NewInt(3),
|
||||||
EIP158Block: big.NewInt(3),
|
EIP158Block: big.NewInt(3),
|
||||||
|
MetropolisBlock: TestNetMetropolisBlock,
|
||||||
|
|
||||||
Clique: &CliqueConfig{
|
Clique: &CliqueConfig{
|
||||||
Period: 15,
|
Period: 15,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
@ -99,10 +101,10 @@ type ChainConfig struct {
|
|||||||
EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork)
|
EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork)
|
||||||
EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (fast sync aid)
|
EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (fast sync aid)
|
||||||
|
|
||||||
EIP155Block *big.Int `json:"eip155Block"` // EIP155 HF block
|
EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block
|
||||||
EIP158Block *big.Int `json:"eip158Block"` // EIP158 HF block
|
EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block
|
||||||
|
|
||||||
MetropolisBlock *big.Int `json:"metropolisBlock"` // Metropolis switch block (nil = no fork, 0 = alraedy on homestead)
|
MetropolisBlock *big.Int `json:"metropolisBlock,omitempty"` // Metropolis switch block (nil = no fork, 0 = alraedy on homestead)
|
||||||
|
|
||||||
// Various consensus engines
|
// Various consensus engines
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
@ -174,6 +176,10 @@ func (c *ChainConfig) IsEIP158(num *big.Int) bool {
|
|||||||
return isForked(c.EIP158Block, num)
|
return isForked(c.EIP158Block, num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ChainConfig) IsMetropolis(num *big.Int) bool {
|
||||||
|
return isForked(c.MetropolisBlock, num)
|
||||||
|
}
|
||||||
|
|
||||||
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
|
// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice).
|
||||||
//
|
//
|
||||||
// The returned GasTable's fields shouldn't, under any circumstances, be changed.
|
// The returned GasTable's fields shouldn't, under any circumstances, be changed.
|
||||||
@ -231,6 +237,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
|
|||||||
if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) {
|
if c.IsEIP158(head) && !configNumEqual(c.ChainId, newcfg.ChainId) {
|
||||||
return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
|
return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
|
||||||
}
|
}
|
||||||
|
if isForkIncompatible(c.MetropolisBlock, newcfg.MetropolisBlock, head) {
|
||||||
|
return newCompatError("Metropolis fork block", c.MetropolisBlock, newcfg.MetropolisBlock)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,13 +267,6 @@ func configNumEqual(x, y *big.Int) bool {
|
|||||||
return x.Cmp(y) == 0
|
return x.Cmp(y) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChainConfig) IsMetropolis(num *big.Int) bool {
|
|
||||||
if c.MetropolisBlock == nil || num == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return num.Cmp(c.MetropolisBlock) >= 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigCompatError is raised if the locally-stored blockchain is initialised with a
|
// ConfigCompatError is raised if the locally-stored blockchain is initialised with a
|
||||||
// ChainConfig that would alter the past.
|
// ChainConfig that would alter the past.
|
||||||
type ConfigCompatError struct {
|
type ConfigCompatError struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user