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

fix: precompile revert for abci1.0 #25

Draft
wants to merge 1 commit into
base: basechain/abci1.0/develop
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion x/evm/statedb/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ func (ch accessListAddSlotChange) dirtied() *common.Address {
}

func (ch precompileChange) revert(s *StateDB) {
s.RevertWithMultiStoreSnapshot(ch.ms)
s.cacheCtx = s.cacheCtx.WithMultiStore(ch.ms)
s.writeCache = func() {
s.cacheCtx.EventManager().EmitEvents(ch.es)
ch.ms.CacheMultiStore().Write()
}
}

func (ch precompileChange) dirtied() *common.Address {
Expand Down
37 changes: 15 additions & 22 deletions x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,32 +312,25 @@ func (s *StateDB) MultiStoreSnapshot() (sdk.CacheMultiStore, error) {
return snapshot, nil
}

func (s *StateDB) RevertWithMultiStoreSnapshot(snapshot sdk.MultiStore) {
s.cacheCtx = s.cacheCtx.
WithMultiStore(snapshot).
WithEventManager(sdk.NewEventManager())
}

// If revert is occurred, the snapshot of journal is overwrited to MultiStore of ctx.
// The events is just for debug.
func (s *StateDB) PostPrecompileProcessing(snapshot sdk.MultiStore, events sdk.Events, contract common.Address, converter EventConverter) {
func (s *StateDB) ProcessPrecompileEvents(contract common.Address, events sdk.Events, converter EventConverter) {
// convert native events to evm logs
if converter != nil && len(events) > 0 {
for _, event := range events {
log, err := converter(event)
if err != nil {
s.ctx.Logger().Error("failed to convert event", "err", err)
continue
}
if log == nil {
continue
}

log.Address = contract
s.AddLog(log)
for _, event := range events {
log, err := converter(event)
if err != nil {
s.ctx.Logger().Error("failed to convert event", "err", err)
continue
}
if log == nil {
continue
}

log.Address = contract
s.AddLog(log)
}
}

// If revert is occurred, the snapshot of journal is overwritten.
func (s *StateDB) AddPrecompileSnapshot(snapshot sdk.MultiStore, events sdk.Events) {
s.journal.append(precompileChange{snapshot, events})
}

Expand Down
Loading