@@ -188,10 +188,18 @@ export class ChainhookPgStore extends BasePgStoreModule {
188188 network_id : messageData . mock_proposal . peer_info . network_id ,
189189 index_block_hash : normalizeHexString ( messageData . mock_proposal . peer_info . index_block_hash ) ,
190190 } ;
191- await sql `
191+ const result = await sql `
192192 INSERT INTO mock_blocks ${ sql ( dbMockBlock ) }
193+ ON CONFLICT ON CONSTRAINT mock_blocks_idb_unique DO NOTHING
193194 ` ;
194195
196+ if ( result . count === 0 ) {
197+ logger . info (
198+ `Skipped inserting duplicate mock block height=${ dbMockBlock . stacks_tip_height } , hash=${ dbMockBlock . stacks_tip } `
199+ ) ;
200+ return ;
201+ }
202+
195203 for ( const batch of batchIterate ( messageData . mock_signatures , 500 ) ) {
196204 const sigs = batch . map ( sig => {
197205 const dbSig : DbMockBlockSignerSignature = {
@@ -235,9 +243,15 @@ export class ChainhookPgStore extends BasePgStoreModule {
235243 // Metadata fields
236244 metadata_server_version : messageData . metadata . server_version ,
237245 } ;
238- await sql `
246+ const result = await sql `
239247 INSERT INTO mock_signatures ${ sql ( dbMockSignature ) }
248+ ON CONFLICT ON CONSTRAINT mock_signatures_signer_key_idb_unique DO NOTHING
240249 ` ;
250+ if ( result . count === 0 ) {
251+ logger . info (
252+ `Skipped inserting duplicate mock signature height=${ dbMockSignature . stacks_tip_height } , hash=${ dbMockSignature . stacks_tip } , signer=${ dbMockSignature . signer_key } `
253+ ) ;
254+ }
241255 }
242256
243257 private async applyMockProposal (
@@ -258,9 +272,15 @@ export class ChainhookPgStore extends BasePgStoreModule {
258272 network_id : messageData . network_id ,
259273 index_block_hash : normalizeHexString ( messageData . index_block_hash ) ,
260274 } ;
261- await sql `
275+ const result = await sql `
262276 INSERT INTO mock_proposals ${ sql ( dbMockProposal ) }
277+ ON CONFLICT ON CONSTRAINT mock_proposals_idb_unique DO NOTHING
263278 ` ;
279+ if ( result . count === 0 ) {
280+ logger . info (
281+ `Skipped inserting duplicate mock proposal height=${ dbMockProposal . stacks_tip_height } , hash=${ dbMockProposal . stacks_tip } `
282+ ) ;
283+ }
264284 }
265285
266286 private async applyBlockProposal (
@@ -332,7 +352,7 @@ export class ChainhookPgStore extends BasePgStoreModule {
332352
333353 if ( result . count === 0 ) {
334354 logger . info (
335- `Skipped inserting duplicate block response signer_key =${ dbBlockResponse . signer_key } , hash=${ dbBlockResponse . signer_sighash } `
355+ `Skipped inserting duplicate block response signer =${ dbBlockResponse . signer_key } , hash=${ dbBlockResponse . signer_sighash } `
336356 ) ;
337357 }
338358 }
0 commit comments