Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加分叉逻辑 #2258

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
// we'll set the default jump table.
if cfg.JumpTable[STOP] == nil {
if evm.StateDB == nil {
cfg.JumpTable = londonInstructionSet
} else if evm.chainRules.IsPauli || gov.Gte150VersionState(evm.StateDB) {
cfg.JumpTable = londonInstructionSet
cfg.JumpTable = shanghaiInstructionSet
} else if evm.chainRules.IsDirac || gov.Gte160VersionState(evm.StateDB) {
cfg.JumpTable = shanghaiInstructionSet
} else {
cfg.JumpTable = istanbulInstructionSet
cfg.JumpTable = londonInstructionSet
}
}

Expand Down
11 changes: 9 additions & 2 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ var (
//homesteadInstructionSet = newHomesteadInstructionSet()
//byzantiumInstructionSet = newByzantiumInstructionSet()
//constantinopleInstructionSet = newConstantinopleInstructionSet()
istanbulInstructionSet = newIstanbulInstructionSet()
//istanbulInstructionSet = newIstanbulInstructionSet()
//berlinInstructionSet = newBerlinInstructionSet()
londonInstructionSet = newLondonInstructionSet()
londonInstructionSet = newLondonInstructionSet()
shanghaiInstructionSet = newShanghaiInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
Expand All @@ -78,6 +79,12 @@ func validate(jt JumpTable) JumpTable {
return jt
}

func newShanghaiInstructionSet() JumpTable {
instructionSet := newLondonInstructionSet()
//enable3860(&instructionSet) // Limit and meter initcode
return validate(instructionSet)
}

// newLondonInstructionSet returns the frontier, homestead, byzantium,
// contantinople, istanbul, petersburg, berlin and london instructions.
func newLondonInstructionSet() JumpTable {
Expand Down
32 changes: 28 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var (
EinsteinBlock: big.NewInt(1),
HubbleBlock: big.NewInt(1),
PauliBlock: big.NewInt(1),
DiracBlock: big.NewInt(1),
Cbft: &CbftConfig{
InitialNodes: ConvertNodeUrl(initialTestnetConsensusNodes),
Amount: 10,
Expand Down Expand Up @@ -144,6 +145,7 @@ var (
EinsteinBlock: big.NewInt(0),
HubbleBlock: big.NewInt(0),
PauliBlock: big.NewInt(0),
DiracBlock: big.NewInt(0),
Cbft: &CbftConfig{
Period: 3,
},
Expand All @@ -155,7 +157,7 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), PrivatePIP7ChainID, "lat", "", big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), &CbftConfig{Period: 3}, FORKVERSION_1_5_0, false, sync.RWMutex{}}
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), PrivatePIP7ChainID, "lat", "", big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), &CbftConfig{Period: 3}, FORKVERSION_1_5_0, false, sync.RWMutex{}}

PrivatePIP7ChainID = new(big.Int).SetUint64(2203181)
)
Expand Down Expand Up @@ -190,6 +192,7 @@ type ChainConfig struct {
EinsteinBlock *big.Int `json:"einsteinBlock,omitempty"`
HubbleBlock *big.Int `json:"hubbleBlock,omitempty"`
PauliBlock *big.Int `json:"pauliBlock,omitempty"`
DiracBlock *big.Int `json:"diracBlock,omitempty"`

// Various consensus engines
Cbft *CbftConfig `json:"cbft,omitempty"`
Expand All @@ -212,7 +215,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
return fmt.Sprintf("{ChainID: %v PIP7ChainID: %v EIP155: %v Copernicus: %v newton: %v einstein: %v hubble: %v Pauli: %v Engine: %v }",
return fmt.Sprintf("{ChainID: %v PIP7ChainID: %v EIP155: %v Copernicus: %v newton: %v einstein: %v hubble: %v Pauli: %v Dirac: %v Engine: %v }",
c.ChainID,
c.PIP7ChainID,
c.EIP155Block,
Expand All @@ -221,6 +224,7 @@ func (c *ChainConfig) String() string {
c.EinsteinBlock,
c.HubbleBlock,
c.PauliBlock,
c.DiracBlock,
engine,
)
}
Expand Down Expand Up @@ -275,6 +279,25 @@ func (c *ChainConfig) SetPauliBlock(block *big.Int) {
c.PauliBlock = block
}

// version 1.6.0
func (c *ChainConfig) isDirac(num *big.Int) bool {
c.RWMutex.RLock()
defer c.RWMutex.RUnlock()
return isForked(c.DiracBlock, num)
}

func (c *ChainConfig) GetDiracBlock() *big.Int {
c.RWMutex.RLock()
defer c.RWMutex.RUnlock()
return c.DiracBlock
}

func (c *ChainConfig) SetDiracBlock(block *big.Int) {
c.RWMutex.Lock()
defer c.RWMutex.Unlock()
c.DiracBlock = block
}

// 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.
Expand Down Expand Up @@ -422,8 +445,8 @@ func (err *ConfigCompatError) Error() string {
// Rules is a one time interface meaning that it shouldn't be used in between transition
// phases.
type Rules struct {
ChainID *big.Int
IsEIP155, IsCopernicus, IsNewton, IsEinstein, IsHubble, IsPauli bool
ChainID *big.Int
IsEIP155, IsCopernicus, IsNewton, IsEinstein, IsHubble, IsPauli, IsDirac bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -440,5 +463,6 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsEinstein: c.IsEinstein(num),
IsHubble: c.IsHubble(num),
IsPauli: c.IsPauli(num),
IsDirac: c.isDirac(num),
}
}
4 changes: 2 additions & 2 deletions params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
const (
//These versions are meaning the current code version.
VersionMajor = 1 // Major version component of the current release
VersionMinor = 5 // Minor version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMinor = 6 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionMeta = "unstable" // Version metadata to append to the version string

//CAUTION: DO NOT MODIFY THIS ONCE THE CHAIN HAS BEEN INITIALIZED!!!
Expand Down
1 change: 1 addition & 0 deletions params/version_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ const (
FORKVERSION_1_3_0 = uint32(1<<16 | 3<<8 | 0)
FORKVERSION_1_4_0 = uint32(1<<16 | 4<<8 | 0)
FORKVERSION_1_5_0 = uint32(1<<16 | 5<<8 | 0)
FORKVERSION_1_6_0 = uint32(1<<16 | 6<<8 | 0)
)
8 changes: 8 additions & 0 deletions x/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func Gte150Version(version uint32) bool {
return version >= params.FORKVERSION_1_5_0
}

func Gte160VersionState(state xcom.StateDB) bool {
return Gte160Version(GetCurrentActiveVersion(state))
}

func Gte160Version(version uint32) bool {
return version >= params.FORKVERSION_1_6_0
}

func WriteEcHash130(state xcom.StateDB) error {
if data, err := xcom.EcParams130(); nil != err {
return err
Expand Down
Loading