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

Synchronizer stores the accumulated input hash #1535

Merged
merged 1 commit into from
Jan 13, 2023
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
96 changes: 60 additions & 36 deletions sequencer/mocks/mock_db_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions sequencer/mocks/mock_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 49 additions & 19 deletions sequencer/mocks/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sequencer/mocks/mock_worker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions state/pgstatestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,3 +1987,11 @@ func (p *PostgresStorage) GetLastClosedBatch(ctx context.Context, dbTx pgx.Tx) (
}
return &batch, nil
}

// AddAccumulatedInputHash adds the accumulated input hash
func (p *PostgresStorage) AddAccumulatedInputHash(ctx context.Context, batchNum uint64, accInputHash common.Hash, dbTx pgx.Tx) error {
AddAccInputHashBatchSQL := "UPDATE state.batch SET acc_input_hash = $1 WHERE batch_num = $2"
e := p.getExecQuerier(dbTx)
_, err := e.Exec(ctx, AddAccInputHashBatchSQL, accInputHash.String(), batchNum)
return err
}
34 changes: 34 additions & 0 deletions state/pgstatestorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,37 @@ func TestVerifiedBatch(t *testing.T) {

require.NoError(t, dbTx.Commit(ctx))
}

func TestAddAccumulatedInputHash(t *testing.T) {
initOrResetDB()

ctx := context.Background()
dbTx, err := testState.BeginStateTransaction(ctx)
require.NoError(t, err)

block := &state.Block{
BlockNumber: 1,
BlockHash: common.HexToHash("0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"),
ParentHash: common.HexToHash("0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"),
ReceivedAt: time.Now(),
}
err = testState.AddBlock(ctx, block, dbTx)
assert.NoError(t, err)

_, err = testState.PostgresStorage.Exec(ctx, `INSERT INTO state.batch
(batch_num, global_exit_root, local_exit_root, state_root, timestamp, coinbase, raw_txs_data)
VALUES(1, '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000', '0xbf34f9a52a63229e90d1016011655bc12140bba5b771817b88cbf340d08dcbde', '2022-12-19 08:17:45.000', '0x0000000000000000000000000000000000000000', NULL);
`)
require.NoError(t, err)

accInputHash := common.HexToHash("0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f2")
batchNum := uint64(1)
err = testState.AddAccumulatedInputHash(ctx, batchNum, accInputHash, dbTx)
require.NoError(t, err)

b, err := testState.GetBatchByNumber(ctx, batchNum, dbTx)
require.NoError(t, err)
assert.Equal(t, b.BatchNumber, batchNum)
assert.Equal(t, b.AccInputHash, accInputHash)
require.NoError(t, dbTx.Commit(ctx))
}
Loading