-
Notifications
You must be signed in to change notification settings - Fork 324
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
[evm] EIP-1153 enable transient storage feature #4214
Changes from 12 commits
4ab40f0
16f63a0
75b545c
47bf31c
9bf2c28
cd7beb2
64d1b5d
4f12e20
5d00100
095ca75
214787c
3a19630
46adced
77d80fd
5c25a48
34b94d6
d5656e4
03ac0dd
4b76ef0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,16 @@ func TestConstantinople(t *testing.T) { | |
action.EmptyAddress, | ||
29275561, | ||
}, | ||
// after Tsunami - Upernavik | ||
{ | ||
action.EmptyAddress, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be "io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y" |
||
39275360, | ||
}, | ||
// after Upernavik | ||
{ | ||
action.EmptyAddress, | ||
39275562, | ||
}, | ||
{ | ||
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y", | ||
1261440000, // = 200*365*24*3600/5, around 200 years later | ||
|
@@ -355,8 +365,10 @@ func TestConstantinople(t *testing.T) { | |
require.Equal(isSumatra, chainRules.IsMerge) | ||
require.Equal(isSumatra, chainRules.IsShanghai) | ||
|
||
// Cancun, Prague not yet enabled | ||
require.False(evmChainConfig.IsCancun(big.NewInt(int64(e.height)), evm.Context.Time)) | ||
// Upernavik = enable Cancun | ||
isUpernavik := g.IsUpernavik(e.height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments need updates |
||
require.Equal(isUpernavik, chainRules.IsCancun) | ||
//Prague not yet enabled | ||
require.False(evmChainConfig.IsPrague(big.NewInt(int64(e.height)), evm.Context.Time)) | ||
|
||
// test basefee | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,24 +43,27 @@ | |
|
||
// StateDBAdapter represents the state db adapter for evm to access iotx blockchain | ||
StateDBAdapter struct { | ||
sm protocol.StateManager | ||
logs []*action.Log | ||
transactionLogs []*action.TransactionLog | ||
err error | ||
blockHeight uint64 | ||
executionHash hash.Hash256 | ||
lastAddBalanceAddr string | ||
lastAddBalanceAmount *big.Int | ||
refund uint64 | ||
refundSnapshot map[int]uint64 | ||
cachedContract contractMap | ||
contractSnapshot map[int]contractMap // snapshots of contracts | ||
selfDestructed deleteAccount // account/contract calling SelfDestruct | ||
selfDestructedSnapshot map[int]deleteAccount // snapshots of SelfDestruct accounts | ||
preimages preimageMap | ||
preimageSnapshot map[int]preimageMap | ||
accessList *accessList // per-transaction access list | ||
accessListSnapshot map[int]*accessList | ||
sm protocol.StateManager | ||
logs []*action.Log | ||
transactionLogs []*action.TransactionLog | ||
err error | ||
blockHeight uint64 | ||
executionHash hash.Hash256 | ||
lastAddBalanceAddr string | ||
lastAddBalanceAmount *big.Int | ||
refund uint64 | ||
refundSnapshot map[int]uint64 | ||
cachedContract contractMap | ||
contractSnapshot map[int]contractMap // snapshots of contracts | ||
selfDestructed deleteAccount // account/contract calling SelfDestruct | ||
selfDestructedSnapshot map[int]deleteAccount // snapshots of SelfDestruct accounts | ||
preimages preimageMap | ||
preimageSnapshot map[int]preimageMap | ||
accessList *accessList // per-transaction access list | ||
accessListSnapshot map[int]*accessList | ||
// Transient storage | ||
transientStorage transientStorage | ||
transientStorageSnapshot map[int]transientStorage | ||
logsSnapshot map[int]int // logs is an array, save len(logs) at time of snapshot suffices | ||
txLogsSnapshot map[int]int | ||
notFixTopicCopyBug bool | ||
|
@@ -170,23 +173,25 @@ | |
opts ...StateDBAdapterOption, | ||
) (*StateDBAdapter, error) { | ||
s := &StateDBAdapter{ | ||
sm: sm, | ||
logs: []*action.Log{}, | ||
err: nil, | ||
blockHeight: blockHeight, | ||
executionHash: executionHash, | ||
lastAddBalanceAmount: new(big.Int), | ||
refundSnapshot: make(map[int]uint64), | ||
cachedContract: make(contractMap), | ||
contractSnapshot: make(map[int]contractMap), | ||
selfDestructed: make(deleteAccount), | ||
selfDestructedSnapshot: make(map[int]deleteAccount), | ||
preimages: make(preimageMap), | ||
preimageSnapshot: make(map[int]preimageMap), | ||
accessList: newAccessList(), | ||
accessListSnapshot: make(map[int]*accessList), | ||
logsSnapshot: make(map[int]int), | ||
txLogsSnapshot: make(map[int]int), | ||
sm: sm, | ||
logs: []*action.Log{}, | ||
err: nil, | ||
blockHeight: blockHeight, | ||
executionHash: executionHash, | ||
lastAddBalanceAmount: new(big.Int), | ||
refundSnapshot: make(map[int]uint64), | ||
cachedContract: make(contractMap), | ||
contractSnapshot: make(map[int]contractMap), | ||
selfDestructed: make(deleteAccount), | ||
selfDestructedSnapshot: make(map[int]deleteAccount), | ||
preimages: make(preimageMap), | ||
preimageSnapshot: make(map[int]preimageMap), | ||
accessList: newAccessList(), | ||
accessListSnapshot: make(map[int]*accessList), | ||
transientStorage: newTransientStorage(), | ||
transientStorageSnapshot: make(map[int]transientStorage), | ||
logsSnapshot: make(map[int]int), | ||
txLogsSnapshot: make(map[int]int), | ||
} | ||
for _, opt := range opts { | ||
if err := opt(s); err != nil { | ||
|
@@ -478,13 +483,16 @@ | |
|
||
// SetTransientState sets transient storage for a given account | ||
func (stateDB *StateDBAdapter) SetTransientState(addr common.Address, key, value common.Hash) { | ||
log.S().Panic("SetTransientState not implemented") | ||
prev := stateDB.transientStorage.Get(addr, key) | ||
if prev == value { | ||
return | ||
} | ||
stateDB.transientStorage.Set(addr, key, value) | ||
} | ||
|
||
// GetTransientState gets transient storage for a given account. | ||
func (stateDB *StateDBAdapter) GetTransientState(addr common.Address, key common.Hash) common.Hash { | ||
log.S().Panic("GetTransientState not implemented") | ||
return common.Hash{} | ||
return stateDB.transientStorage.Get(addr, key) | ||
} | ||
|
||
// Selfdestruct6780 implements EIP-6780 | ||
|
@@ -547,6 +555,8 @@ | |
if rules.IsShanghai { // EIP-3651: warm coinbase | ||
stateDB.AddAddressToAccessList(coinbase) | ||
} | ||
// Reset transient storage at the beginning of transaction execution | ||
stateDB.transientStorage = newTransientStorage() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing, not necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is best to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discused, let's remove this, it is done in |
||
} | ||
|
||
// AddressInAccessList returns true if the given address is in the access list | ||
|
@@ -623,6 +633,18 @@ | |
} | ||
} | ||
} | ||
//restore transientStorage | ||
stateDB.transientStorage = stateDB.transientStorageSnapshot[snapshot] | ||
{ | ||
delete(stateDB.transientStorageSnapshot, snapshot) | ||
for i := snapshot + 1; ; i++ { | ||
if _, ok := stateDB.transientStorageSnapshot[i]; ok { | ||
delete(stateDB.transientStorageSnapshot, i) | ||
} else { | ||
break | ||
} | ||
} | ||
} | ||
// restore logs and txLogs | ||
if stateDB.revertLog { | ||
stateDB.logs = stateDB.logs[:stateDB.logsSnapshot[snapshot]] | ||
|
@@ -750,6 +772,8 @@ | |
stateDB.preimageSnapshot[sn] = p | ||
// save a copy of access list | ||
stateDB.accessListSnapshot[sn] = stateDB.accessList.Copy() | ||
// save a copy of transient storage | ||
stateDB.transientStorageSnapshot[sn] = stateDB.transientStorage.Copy() | ||
millken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return sn | ||
} | ||
|
||
|
@@ -1089,6 +1113,8 @@ | |
stateDB.preimageSnapshot = make(map[int]preimageMap) | ||
stateDB.accessList = newAccessList() | ||
stateDB.accessListSnapshot = make(map[int]*accessList) | ||
stateDB.transientStorage = newTransientStorage() | ||
stateDB.transientStorageSnapshot = make(map[int]transientStorage) | ||
stateDB.logsSnapshot = make(map[int]int) | ||
stateDB.txLogsSnapshot = make(map[int]int) | ||
stateDB.logs = []*action.Log{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this comment line should be at L255