Skip to content

Commit

Permalink
Support bsc mainnet hardfork at block height 27,281,024 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmbeing committed Mar 28, 2023
1 parent 6189921 commit 3da15fc
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
11 changes: 4 additions & 7 deletions consensus/parlia/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ledgerwatch/log/v3"
)

func backOffTime(snap *Snapshot, header *types.Header, val libcommon.Address, chainConfig *chain.Config ) uint64 {
func backOffTime(snap *Snapshot, header *types.Header, val libcommon.Address, chainConfig *chain.Config) uint64 {
if snap.inturn(val) {
return 0
} else {
Expand All @@ -29,17 +29,14 @@ func backOffTime(snap *Snapshot, header *types.Header, val libcommon.Address, ch
recentsMap[recent] = seen
}

// if the validator has recently signed, it is unexpected, stop here.
if seen, ok := recentsMap[val]; ok {
log.Error("unreachable code, validator signed recently",
"block", header.Number, "address", val,
"seen", seen, "len(snap.Recents)", len(snap.Recents))
// The backOffTime does not matter when a validator has signed recently.
if _, ok := recentsMap[val]; ok {
return 0
}

inTurnAddr := validators[(snap.Number+1)%uint64(len(validators))]
if _, ok := recentsMap[inTurnAddr]; ok {
log.Info("in turn validator has recently signed, skip initialBackOffTime",
log.Debug("in turn validator has recently signed, skip initialBackOffTime",
"inTurnAddr", inTurnAddr)
delay = 0
}
Expand Down
4 changes: 2 additions & 2 deletions core/systemcontracts/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func init() {
}

PlanckUpgrade[networkname.ChapelChainName] = &Upgrade{
UpgradeName:"planck",
UpgradeName: "planck",
Configs: []*UpgradeConfig{
{
ContractAddr: SlashContract,
Expand All @@ -527,7 +527,7 @@ func init() {
},
}

PlanckUpgrade[networkname.RialtoChainName] = &Upgrade{
PlanckUpgrade[networkname.RialtoChainName] = &Upgrade{
UpgradeName: "planck",
Configs: []*UpgradeConfig{
{
Expand Down
2 changes: 1 addition & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var PrecompiledContractsPlanck = map[libcommon.Address]PrecompiledContract{
}

var (
PrecompiledAddressesPlanck []libcommon.Address
PrecompiledAddressesPlanck []libcommon.Address
PrecompiledAddressesMoran []libcommon.Address
PrecompiledAddressesNano []libcommon.Address
PrecompiledAddressesBerlin []libcommon.Address
Expand Down
7 changes: 6 additions & 1 deletion core/vm/contracts_lightclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const (
// 32 bytes | | |
func decodeTendermintHeaderValidationInput(input []byte) (*lightclient.ConsensusState, *lightclient.Header, error) {
csLen := binary.BigEndian.Uint64(input[consensusStateLengthBytesLength-uint64TypeLength : consensusStateLengthBytesLength])

if consensusStateLengthBytesLength+csLen < consensusStateLengthBytesLength {
return nil, nil, fmt.Errorf("integer overflow, csLen: %d", csLen)
}

if uint64(len(input)) <= consensusStateLengthBytesLength+csLen {
return nil, nil, fmt.Errorf("expected payload size %d, actual size: %d", consensusStateLengthBytesLength+csLen, len(input))
}
Expand Down Expand Up @@ -321,4 +326,4 @@ func keyVerifier(key string) error {
return cmn.NewError("key should not start with x:")
}
return nil
}
}
27 changes: 16 additions & 11 deletions core/vm/lightclient/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ func DecodeHeader(input []byte) (*Header, error) {
type KeyVerifier func(string) error

type KeyValueMerkleProof struct {
Key []byte
Value []byte
StoreName string
AppHash []byte
Proof *merkle.Proof
Key []byte
Value []byte
StoreName string
AppHash []byte
Proof *merkle.Proof

keyVerifier KeyVerifier
proofOpsVerifier merkle.ProofOpsVerifier
verifiers []merkle.ProofOpVerifier
proofRuntime *merkle.ProofRuntime
verifiers []merkle.ProofOpVerifier
proofRuntime *merkle.ProofRuntime
}

func (kvmp *KeyValueMerkleProof) SetProofRuntime(prt *merkle.ProofRuntime) {
Expand Down Expand Up @@ -270,16 +270,18 @@ func DecodeKeyValueMerkleProof(input []byte) (*KeyValueMerkleProof, error) {
inputLength := uint64(len(input))
pos := uint64(0)

if inputLength <= storeNameLengthBytesLength+keyLengthBytesLength+valueLengthBytesLength+appHashLength {
return nil, fmt.Errorf("input length should be no less than %d", storeNameLengthBytesLength+keyLengthBytesLength+valueLengthBytesLength+appHashLength)
fixedSize := storeNameLengthBytesLength + keyLengthBytesLength + valueLengthBytesLength + appHashLength
if inputLength <= fixedSize {
return nil, fmt.Errorf("input length should be no less than %d", fixedSize)
}
storeName := string(bytes.Trim(input[pos:pos+storeNameLengthBytesLength], "\x00"))
pos += storeNameLengthBytesLength

keyLength := binary.BigEndian.Uint64(input[pos+keyLengthBytesLength-8 : pos+keyLengthBytesLength])
pos += keyLengthBytesLength

if inputLength <= storeNameLengthBytesLength+keyLengthBytesLength+keyLength+valueLengthBytesLength {
fixedSize = storeNameLengthBytesLength + keyLengthBytesLength + valueLengthBytesLength
if inputLength <= fixedSize+keyLength || fixedSize+keyLength < fixedSize {
return nil, fmt.Errorf("invalid input, keyLength %d is too long", keyLength)
}
key := input[pos : pos+keyLength]
Expand All @@ -288,7 +290,10 @@ func DecodeKeyValueMerkleProof(input []byte) (*KeyValueMerkleProof, error) {
valueLength := binary.BigEndian.Uint64(input[pos+valueLengthBytesLength-8 : pos+valueLengthBytesLength])
pos += valueLengthBytesLength

if inputLength <= storeNameLengthBytesLength+keyLengthBytesLength+keyLength+valueLengthBytesLength+valueLength+appHashLength {
fixedSize = storeNameLengthBytesLength + keyLengthBytesLength + valueLengthBytesLength + appHashLength
if inputLength <= fixedSize+keyLength+valueLength ||
fixedSize+keyLength < fixedSize ||
fixedSize+keyLength+valueLength < valueLength {
return nil, fmt.Errorf("invalid input, valueLength %d is too long", valueLength)
}
value := input[pos : pos+valueLength]
Expand Down
2 changes: 1 addition & 1 deletion params/chainspecs/bsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"nanoBlock": 21962149,
"moranBlock": 22107423,
"gibbsBlock": 23846001,
"planckBlock": 0,
"planckBlock": 27281024,
"parlia": {
"DBPath": "",
"InMemory": false,
Expand Down
6 changes: 3 additions & 3 deletions params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var (

// see https://calver.org
const (
VersionMajor = 2 // Major version component of the current release
VersionMinor = 40 // Minor version component of the current release
VersionMicro = 0 // Patch version component of the current release
VersionMajor = 2 // Major version component of the current release
VersionMinor = 40 // Minor version component of the current release
VersionMicro = 0 // Patch version component of the current release
VersionModifier = "dev" // Modifier component of the current release
VersionKeyCreated = "ErigonVersionCreated"
VersionKeyFinished = "ErigonVersionFinished"
Expand Down

0 comments on commit 3da15fc

Please sign in to comment.