Skip to content

Commit

Permalink
Prevent overwriting existing payload with empty Payload (#2716)
Browse files Browse the repository at this point in the history
* do not overwrite existing payload with empty payload

* lint

* add comments
  • Loading branch information
imabdulbasit authored Mar 6, 2025
1 parent a2f0fc7 commit 1d535da
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,13 @@ where
// Similarly, we can initialize the payload table with a null payload, which can help us
// distinguish between blocks that haven't been produced yet and blocks we haven't received
// yet when answering queries.
self.upsert("payload", ["height"], ["height"], [(height as i64,)])
.await?;
// We don't overwrite the payload if it already exists.
// During epoch transition in PoS, the same height block is sent multiple times.
// The first block may have the payload, but subsequent blocks might be missing it.
// Overwriting would cause the payload to be lost since the block height is the same
let query = query("INSERT INTO payload (height) VALUES ($1) ON CONFLICT DO NOTHING")
.bind(height as i64);
query.execute(self.as_mut()).await?;

// Finally, we insert the leaf itself, which references the header row we created.
// Serialize the full leaf and QC to JSON for easy storage.
Expand Down

0 comments on commit 1d535da

Please sign in to comment.