diff --git a/hotshot-query-service/src/data_source/storage/sql/transaction.rs b/hotshot-query-service/src/data_source/storage/sql/transaction.rs index efeea128e6..105df2586a 100644 --- a/hotshot-query-service/src/data_source/storage/sql/transaction.rs +++ b/hotshot-query-service/src/data_source/storage/sql/transaction.rs @@ -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.