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

Get IM State root from receipt for data stream. #3400

Merged
merged 3 commits into from
Feb 29, 2024
Merged
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
20 changes: 11 additions & 9 deletions state/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,18 @@ func GenerateDataStreamerFile(ctx context.Context, streamServer *datastreamer.St
}

for _, tx := range l2Block.Txs {
// Populate intermediate state root
if imStateRoots == nil || (*imStateRoots)[blockStart.L2BlockNumber] == nil {
position := GetSystemSCPosition(l2Block.L2BlockNumber)
imStateRoot, err := stateDB.GetStorageAt(ctx, common.HexToAddress(SystemSC), big.NewInt(0).SetBytes(position), l2Block.StateRoot)
if err != nil {
return err
if l2Block.ForkID < FORKID_ETROG {
// Populate intermediate state root with information from the system SC (or cache if available)
if imStateRoots == nil || (*imStateRoots)[blockStart.L2BlockNumber] == nil {
position := GetSystemSCPosition(l2Block.L2BlockNumber)
imStateRoot, err := stateDB.GetStorageAt(ctx, common.HexToAddress(SystemSC), big.NewInt(0).SetBytes(position), l2Block.StateRoot)
if err != nil {
return err
}
tx.StateRoot = common.BigToHash(imStateRoot)
} else {
tx.StateRoot = common.BytesToHash((*imStateRoots)[blockStart.L2BlockNumber])
}
tx.StateRoot = common.BigToHash(imStateRoot)
} else {
tx.StateRoot = common.BytesToHash((*imStateRoots)[blockStart.L2BlockNumber])
}

_, err = streamServer.AddStreamEntry(EntryTypeL2Tx, tx.Encode())
Expand Down
5 changes: 4 additions & 1 deletion state/pgstatestorage/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func scanL2Block(row pgx.Row) (*state.DSL2Block, error) {

// GetDSL2Transactions returns the L2 transactions
func (p *PostgresStorage) GetDSL2Transactions(ctx context.Context, firstL2Block, lastL2Block uint64, dbTx pgx.Tx) ([]*state.DSL2Transaction, error) {
const l2TxSQL = `SELECT l2_block_num, t.effective_percentage, t.encoded
const l2TxSQL = `SELECT l2_block_num, t.effective_percentage, t.encoded, r.post_state
FROM state.transaction t, state.receipt r
WHERE l2_block_num BETWEEN $1 AND $2 AND r.tx_hash = t.hash
ORDER BY t.l2_block_num ASC, r.tx_index ASC`
Expand Down Expand Up @@ -119,10 +119,12 @@ func (p *PostgresStorage) GetDSL2Transactions(ctx context.Context, firstL2Block,
func scanDSL2Transaction(row pgx.Row) (*state.DSL2Transaction, error) {
l2Transaction := state.DSL2Transaction{}
encoded := []byte{}
postState := []byte{}
if err := row.Scan(
&l2Transaction.L2BlockNumber,
&l2Transaction.EffectiveGasPricePercentage,
&encoded,
&postState,
); err != nil {
return nil, err
}
Expand All @@ -139,6 +141,7 @@ func scanDSL2Transaction(row pgx.Row) (*state.DSL2Transaction, error) {
l2Transaction.Encoded = binaryTxData
l2Transaction.EncodedLength = uint32(len(l2Transaction.Encoded))
l2Transaction.IsValid = 1
l2Transaction.StateRoot = common.BytesToHash(postState)
return &l2Transaction, nil
}

Expand Down
Loading