Skip to content

Commit

Permalink
Fix encoding bug in AddForcedBatch
Browse files Browse the repository at this point in the history
The forced_batch table expects the raw_txs_data column to be a
string (specifically a hex encoding of the raw transaction bytes).
The corresponding GetForcedBatch function uses hex.DecodeString to
turn the value of this column back into raw bytes. However,
AddForcedBatch is missing a hex.EncodeToString, so it is actually
interpreting the raw transaction bytes as an ASCII representation
of a hex-encoded string.
  • Loading branch information
jbearer committed Jan 16, 2023
1 parent a8f6318 commit 11ff388
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion state/pgstatestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (p *PostgresStorage) GetTimeForLatestBatchVirtualization(ctx context.Contex
// AddForcedBatch adds a new ForcedBatch to the db
func (p *PostgresStorage) AddForcedBatch(ctx context.Context, forcedBatch *ForcedBatch, tx pgx.Tx) error {
const addForcedBatchSQL = "INSERT INTO state.forced_batch (forced_batch_num, global_exit_root, timestamp, raw_txs_data, coinbase, block_num) VALUES ($1, $2, $3, $4, $5, $6)"
_, err := tx.Exec(ctx, addForcedBatchSQL, forcedBatch.ForcedBatchNumber, forcedBatch.GlobalExitRoot.String(), forcedBatch.ForcedAt, forcedBatch.RawTxsData, forcedBatch.Sequencer.String(), forcedBatch.BlockNumber)
_, err := tx.Exec(ctx, addForcedBatchSQL, forcedBatch.ForcedBatchNumber, forcedBatch.GlobalExitRoot.String(), forcedBatch.ForcedAt, hex.EncodeToString(forcedBatch.RawTxsData), forcedBatch.Sequencer.String(), forcedBatch.BlockNumber)
return err
}

Expand Down

0 comments on commit 11ff388

Please sign in to comment.