@@ -660,17 +660,13 @@ CREATE TABLE IF NOT EXISTS block_signatures (
660
660
-- the sighash is sufficient to uniquely identify the block across all burnchain, PoX,
661
661
-- and stacks forks.
662
662
signer_signature_hash TEXT NOT NULL,
663
- -- the signer address that rejected the block
663
+ -- the signer address that signed the block
664
664
signer_addr TEXT NOT NULL,
665
665
-- signature itself
666
666
signature TEXT NOT NULL,
667
- PRIMARY KEY (signer_addr, signer_signature_hash )
667
+ PRIMARY KEY (signer_signature_hash, signer_addr )
668
668
) STRICT;"# ;
669
669
670
- static CREATE_BLOCK_SIGNATURES_INDEX : & str = r#"
671
- CREATE INDEX IF NOT EXISTS idx_block_signatures_by_sighash ON block_signatures(signer_signature_hash);
672
- "# ;
673
-
674
670
static DROP_BLOCK_REJECTION_SIGNER_ADDRS : & str = r#"
675
671
DROP TABLE IF EXISTS block_rejection_signer_addrs;
676
672
"# ;
@@ -686,13 +682,9 @@ CREATE TABLE IF NOT EXISTS block_rejection_signer_addrs (
686
682
signer_addr TEXT NOT NULL,
687
683
-- the reject reason code
688
684
reject_code INTEGER NOT NULL,
689
- PRIMARY KEY (signer_addr, signer_signature_hash )
685
+ PRIMARY KEY (signer_signature_hash, signer_addr )
690
686
) STRICT;"# ;
691
687
692
- static CREATE_BLOCK_REJECTION_SIGNER_ADDRS_INDEX : & str = r#"
693
- CREATE INDEX IF NOT EXISTS idx_block_rejection_signer_addrs_by_sighash ON block_rejection_signer_addrs(signer_signature_hash);
694
- "# ;
695
-
696
688
static SCHEMA_1 : & [ & str ] = & [
697
689
DROP_SCHEMA_0 ,
698
690
CREATE_DB_CONFIG ,
@@ -806,10 +798,8 @@ static SCHEMA_16: &[&str] = &[
806
798
static SCHEMA_17 : & [ & str ] = & [
807
799
DROP_BLOCK_SIGNATURES_TABLE ,
808
800
CREATE_BLOCK_SIGNATURES_TABLE_V17 ,
809
- CREATE_BLOCK_SIGNATURES_INDEX ,
810
801
DROP_BLOCK_REJECTION_SIGNER_ADDRS ,
811
802
CREATE_BLOCK_REJECTION_SIGNER_ADDRS_V17 ,
812
- CREATE_BLOCK_REJECTION_SIGNER_ADDRS_INDEX ,
813
803
"INSERT INTO db_config (version) VALUES (17);" ,
814
804
] ;
815
805
@@ -1360,13 +1350,23 @@ impl SignerDb {
1360
1350
signer_addr. to_string( ) ,
1361
1351
serde_json:: to_string( signature) . map_err( DBError :: SerializationError ) ?
1362
1352
] ;
1363
-
1364
- debug ! ( "Inserting block signature." ;
1365
- "signer_signature_hash" => %block_sighash,
1366
- "signature" => %signature) ;
1367
-
1368
1353
let rows_added = self . db . execute ( qry, args) ?;
1369
- Ok ( rows_added > 0 )
1354
+
1355
+ let is_new_signature = rows_added > 0 ;
1356
+ if is_new_signature {
1357
+ debug ! ( "Added block signature." ;
1358
+ "signer_signature_hash" => %block_sighash,
1359
+ "signer_address" => %signer_addr,
1360
+ "signature" => %signature
1361
+ ) ;
1362
+ } else {
1363
+ debug ! ( "Duplicate block signature." ;
1364
+ "signer_signature_hash" => %block_sighash,
1365
+ "signer_address" => %signer_addr,
1366
+ "signature" => %signature
1367
+ ) ;
1368
+ }
1369
+ Ok ( is_new_signature)
1370
1370
}
1371
1371
1372
1372
/// Get all signatures for a block
@@ -1391,15 +1391,15 @@ impl SignerDb {
1391
1391
reject_reason : & RejectReason ,
1392
1392
) -> Result < bool , DBError > {
1393
1393
// If this signer/block already has a signature, do not allow a rejection
1394
- let sig_qry = "SELECT 1 FROM block_signatures WHERE signer_signature_hash = ?1 AND signer_addr = ?2 LIMIT 1 " ;
1394
+ let sig_qry = "SELECT EXISTS(SELECT 1 FROM block_signatures WHERE signer_signature_hash = ?1 AND signer_addr = ?2) " ;
1395
1395
let sig_args = params ! [ block_sighash, addr. to_string( ) ] ;
1396
- let has_signature : Option < i64 > = self
1397
- . db
1398
- . query_row ( sig_qry , sig_args , |row| row . get ( 0 ) )
1399
- . optional ( ) ? ;
1400
- if has_signature . is_some ( ) {
1401
- warn ! ( "Cannot add block rejection for signer {} and block {} because a signature already exists." ,
1402
- addr , block_sighash ) ;
1396
+ let exists = self . db . query_row ( sig_qry , sig_args , |row| row . get ( 0 ) ) ? ;
1397
+ if exists {
1398
+ warn ! ( "Cannot add block rejection because a signature already exists." ;
1399
+ "signer_signature_hash" => %block_sighash ,
1400
+ "signer_address" => %addr ,
1401
+ "reject_reason" => %reject_reason
1402
+ ) ;
1403
1403
return Ok ( false ) ;
1404
1404
}
1405
1405
@@ -1414,6 +1414,11 @@ impl SignerDb {
1414
1414
match existing_code {
1415
1415
Some ( code) if code == reject_code => {
1416
1416
// Row exists with same reject_reason, do nothing
1417
+ debug ! ( "Duplicate block rejection." ;
1418
+ "signer_signature_hash" => %block_sighash,
1419
+ "signer_address" => %addr,
1420
+ "reject_reason" => %reject_reason
1421
+ ) ;
1417
1422
Ok ( false )
1418
1423
}
1419
1424
Some ( _) => {
0 commit comments