From 270645155af4e5b42fbe22f85f6124bebb95580e Mon Sep 17 00:00:00 2001 From: Diego Nava Date: Mon, 25 Sep 2023 13:42:14 +0200 Subject: [PATCH] write preimages on process --- core/preimages.go | 2 +- core/state_processor.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/preimages.go b/core/preimages.go index 2ca1545a4..dcca3f0e1 100644 --- a/core/preimages.go +++ b/core/preimages.go @@ -347,7 +347,7 @@ func VerifyPreimages(header *block.Header, chain BlockChain) (uint64, error) { if len(preimage) == 0 { return 0, errors.New( fmt.Sprintf( - "cannot find preimage for %x", key, + "cannot find preimage for %x after '%d' accounts", key, existingPreimages, ), ) } diff --git a/core/state_processor.go b/core/state_processor.go index 04974f7be..b1eb04d87 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -169,6 +169,8 @@ func (p *StateProcessor) Process( if len(stakeMsgs) > 0 { blockStakeMsgs = append(blockStakeMsgs, stakeMsgs...) } + + StorePreimageFromTx(statedb, tx) allLogs = append(allLogs, receipt.Logs...) } utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("Process Normal Txns") @@ -685,3 +687,15 @@ func generateOneMigrationMessage( } return nil, nil } + +func StorePreimageFromTx(statedb *state.DB, tx *types.Transaction) { + sender, _ := tx.SenderAddress() + + _ = rawdb.WritePreimages(statedb.Database().DiskDB(), + map[common.Hash][]byte{ + crypto.Keccak256Hash(sender.Bytes()): append(sender.Bytes()), + crypto.Keccak256Hash(tx.To().Bytes()): append(tx.To().Bytes()), + }, + ) + +}