Skip to content
Open
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
3 changes: 3 additions & 0 deletions common/constants.all.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type constant struct {
tipEpochHalving *big.Int
eip1559Block *big.Int
cancunBlock *big.Int
pragueBlock *big.Int

trc21IssuerSMC Address
xdcxListingSMC Address
Expand Down Expand Up @@ -98,6 +99,7 @@ var (
TIPXDCXReceiverDisable = MaintnetConstant.tipXDCXReceiverDisable
Eip1559Block = MaintnetConstant.eip1559Block
CancunBlock = MaintnetConstant.cancunBlock
PragueBlock = MaintnetConstant.pragueBlock
TIPUpgradeReward = MaintnetConstant.tipUpgradeReward
TipUpgradePenalty = MaintnetConstant.tipUpgradePenalty
TIPEpochHalving = MaintnetConstant.tipEpochHalving
Expand Down Expand Up @@ -160,6 +162,7 @@ func CopyConstants(chainID uint64) {
TIPXDCXReceiverDisable = c.tipXDCXReceiverDisable
Eip1559Block = c.eip1559Block
CancunBlock = c.cancunBlock
PragueBlock = c.pragueBlock
TIPUpgradeReward = c.tipUpgradeReward
TipUpgradePenalty = c.tipUpgradePenalty
TIPEpochHalving = c.tipEpochHalving
Expand Down
1 change: 1 addition & 0 deletions common/constants.devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var DevnetConstant = constant{
tipXDCXReceiverDisable: big.NewInt(0),
eip1559Block: big.NewInt(32400),
cancunBlock: big.NewInt(43200),
pragueBlock: big.NewInt(9999999999),
tipUpgradeReward: big.NewInt(9999999999),
tipUpgradePenalty: big.NewInt(9999999999),
tipEpochHalving: big.NewInt(9999999999),
Expand Down
1 change: 1 addition & 0 deletions common/constants.local.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var localConstant = constant{
tipXDCXReceiverDisable: big.NewInt(0),
eip1559Block: big.NewInt(0),
cancunBlock: big.NewInt(0),
pragueBlock: big.NewInt(9999999999),
tipUpgradeReward: big.NewInt(999999999),
tipUpgradePenalty: big.NewInt(999999999),
tipEpochHalving: big.NewInt(999999999),
Expand Down
1 change: 1 addition & 0 deletions common/constants.mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var MaintnetConstant = constant{
tipXDCXReceiverDisable: big.NewInt(80370900), // Target 2nd Oct 2024, safer to release after disable miner
eip1559Block: big.NewInt(9999999999),
cancunBlock: big.NewInt(9999999999),
pragueBlock: big.NewInt(9999999999),
tipUpgradeReward: big.NewInt(9999999999),
tipUpgradePenalty: big.NewInt(9999999999),
tipEpochHalving: big.NewInt(9999999999),
Expand Down
1 change: 1 addition & 0 deletions common/constants.testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var TestnetConstant = constant{
tipXDCXReceiverDisable: big.NewInt(66825000), // Target 26 Aug 2024
eip1559Block: big.NewInt(71550000), // Target 14th Feb 2025
cancunBlock: big.NewInt(71551800),
pragueBlock: big.NewInt(9999999999),
tipUpgradeReward: big.NewInt(9999999999),
tipUpgradePenalty: big.NewInt(9999999999),
tipEpochHalving: big.NewInt(9999999999),
Expand Down
22 changes: 19 additions & 3 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,25 @@ var (
// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
ErrSenderNoEOA = errors.New("sender not an eoa")

ErrNotXDPoS = errors.New("XDPoS not found in config")

ErrNotFoundM1 = errors.New("list M1 not found ")
// -- XDPoS errors --

ErrNotXDPoS = errors.New("XDPoS not found in config")
ErrNotFoundM1 = errors.New("list M1 not found ")
ErrStopPreparingBlock = errors.New("stop calculating a block not verified by M2")

// -- EIP-7702 errors --

// Message validation errors:
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
)

// EIP-7702 state transition errors.
// Note these are just informational, and do not cause tx execution abort.
var (
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")
ErrAuthorizationNonceOverflow = errors.New("EIP-7702 authorization nonce > 64 bit")
ErrAuthorizationInvalidSignature = errors.New("EIP-7702 authorization has invalid signature")
ErrAuthorizationDestinationHasCode = errors.New("EIP-7702 authorization destination is a contract")
ErrAuthorizationNonceMismatch = errors.New("EIP-7702 authorization nonce does not match current account nonce")
)
70 changes: 39 additions & 31 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math/big"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto"
)

// journalEntry is a modification entry in the state change journal that can be
Expand Down Expand Up @@ -84,38 +85,45 @@ func (j *journal) length() int {
return len(j.entries)
}

func (j *journal) setCode(address common.Address, prevCode []byte) {
j.append(codeChange{
account: address,
prevCode: prevCode,
})
}

type (
// Changes to the account trie.
createObjectChange struct {
account *common.Address
account common.Address
}
resetObjectChange struct {
account *common.Address
account common.Address
prev *stateObject
prevdestruct bool
}
selfDestructChange struct {
account *common.Address
account common.Address
prev bool // whether account had already self-destructed
prevbalance *big.Int
}

// Changes to individual accounts.
balanceChange struct {
account *common.Address
account common.Address
prev *big.Int
}
nonceChange struct {
account *common.Address
account common.Address
prev uint64
}
storageChange struct {
account *common.Address
account common.Address
key, prevalue common.Hash
}
codeChange struct {
account *common.Address
prevcode, prevhash []byte
account common.Address
prevCode []byte
}

// Changes to other state values.
Expand All @@ -129,30 +137,30 @@ type (
hash common.Hash
}
touchChange struct {
account *common.Address
account common.Address
}
// Changes to the access list
accessListAddAccountChange struct {
address *common.Address
address common.Address
}
accessListAddSlotChange struct {
address *common.Address
slot *common.Hash
address common.Address
slot common.Hash
}

transientStorageChange struct {
account *common.Address
account common.Address
key, prevalue common.Hash
}
)

func (ch createObjectChange) revert(s *StateDB) {
delete(s.stateObjects, *ch.account)
delete(s.stateObjectsDirty, *ch.account)
delete(s.stateObjects, ch.account)
delete(s.stateObjectsDirty, ch.account)
}

func (ch createObjectChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch resetObjectChange) revert(s *StateDB) {
Expand All @@ -163,19 +171,19 @@ func (ch resetObjectChange) revert(s *StateDB) {
}

func (ch resetObjectChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch selfDestructChange) revert(s *StateDB) {
obj := s.getStateObject(*ch.account)
obj := s.getStateObject(ch.account)
if obj != nil {
obj.selfDestructed = ch.prev
obj.setBalance(ch.prevbalance)
}
}

func (ch selfDestructChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
Expand All @@ -184,43 +192,43 @@ func (ch touchChange) revert(s *StateDB) {
}

func (ch touchChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch balanceChange) revert(s *StateDB) {
s.getStateObject(*ch.account).setBalance(ch.prev)
s.getStateObject(ch.account).setBalance(ch.prev)
}

func (ch balanceChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch nonceChange) revert(s *StateDB) {
s.getStateObject(*ch.account).setNonce(ch.prev)
s.getStateObject(ch.account).setNonce(ch.prev)
}

func (ch nonceChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch codeChange) revert(s *StateDB) {
s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
s.getStateObject(ch.account).setCode(crypto.Keccak256Hash(ch.prevCode), ch.prevCode)
}

func (ch codeChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch storageChange) revert(s *StateDB) {
s.getStateObject(*ch.account).setState(ch.key, ch.prevalue)
s.getStateObject(ch.account).setState(ch.key, ch.prevalue)
}

func (ch storageChange) dirtied() *common.Address {
return ch.account
return &ch.account
}

func (ch transientStorageChange) revert(s *StateDB) {
s.setTransientState(*ch.account, ch.key, ch.prevalue)
s.setTransientState(ch.account, ch.key, ch.prevalue)
}

func (ch transientStorageChange) dirtied() *common.Address {
Expand Down Expand Up @@ -267,15 +275,15 @@ func (ch accessListAddAccountChange) revert(s *StateDB) {
(addr) at this point, since no storage adds can remain when come upon
a single (addr) change.
*/
s.accessList.DeleteAddress(*ch.address)
s.accessList.DeleteAddress(ch.address)
}

func (ch accessListAddAccountChange) dirtied() *common.Address {
return nil
}

func (ch accessListAddSlotChange) revert(s *StateDB) {
s.accessList.DeleteSlot(*ch.address, *ch.slot)
s.accessList.DeleteSlot(ch.address, ch.slot)
}

func (ch accessListAddSlotChange) dirtied() *common.Address {
Expand Down
22 changes: 10 additions & 12 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"math/big"
"slices"
"time"

"github.com/XinFinOrg/XDPoSChain/common"
Expand Down Expand Up @@ -144,7 +145,7 @@ func (s *stateObject) markSelfdestructed() {

func (s *stateObject) touch() {
s.db.journal.append(touchChange{
account: &s.address,
account: s.address,
})
if s.address == ripemd {
// Explicitly put it in the dirty-cache, which is otherwise generated from
Expand Down Expand Up @@ -230,7 +231,7 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
}
// New value is different, update and journal the change
s.db.journal.append(storageChange{
account: &s.address,
account: s.address,
key: key,
prevalue: prev,
})
Expand Down Expand Up @@ -367,7 +368,7 @@ func (s *stateObject) SubBalance(amount *big.Int, reason tracing.BalanceChangeRe

func (s *stateObject) SetBalance(amount *big.Int, reason tracing.BalanceChangeReason) {
s.db.journal.append(balanceChange{
account: &s.address,
account: s.address,
prev: new(big.Int).Set(s.data.Balance),
})
if s.db.logger != nil && s.db.logger.OnBalanceChange != nil {
Expand Down Expand Up @@ -437,17 +438,14 @@ func (s *stateObject) CodeSize(db Database) int {
return size
}

func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
prevcode := s.Code(s.db.db)
s.db.journal.append(codeChange{
account: &s.address,
prevhash: s.CodeHash(),
prevcode: prevcode,
})
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) []byte {
prevCode := slices.Clone(s.code)
s.db.journal.setCode(s.address, prevCode)
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevcode, codeHash, code)
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevCode, codeHash, code)
}
s.setCode(codeHash, code)
return prevCode
}

func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
Expand All @@ -458,7 +456,7 @@ func (s *stateObject) setCode(codeHash common.Hash, code []byte) {

func (s *stateObject) SetNonce(nonce uint64) {
s.db.journal.append(nonceChange{
account: &s.address,
account: s.address,
prev: s.data.Nonce,
})
if s.db.logger != nil && s.db.logger.OnNonceChange != nil {
Expand Down
Loading
Loading