@@ -151,11 +151,18 @@ impl Wallet {
151
151
bundle_hash BLOB NOT NULL,
152
152
UNIQUE(sidechain_number, bundle_hash));" ,
153
153
) ,
154
+ // TODO: delete this? Not persisting to this table anywhere.
155
+ // Not clear how we're going to keep this in sync with the
156
+ // actual mempool. Seems like we could accomplish the same
157
+ // thing through `listtransactions`
154
158
M :: up(
155
159
"CREATE TABLE mempool
156
160
(txid BLOB UNIQUE NOT NULL,
157
161
tx_data BLOB NOT NULL);" ,
158
162
) ,
163
+ // This is really a table of _pending_ deposits. Gets wiped
164
+ // upon generating a fresh block. How will this work for
165
+ // non-regtest?
159
166
M :: up(
160
167
"CREATE TABLE deposits
161
168
(sidechain_number INTEGER NOT NULL,
@@ -343,22 +350,27 @@ impl Wallet {
343
350
tracing:: info!( "Generate: creating {} blocks" , count) ;
344
351
345
352
for _ in 0 ..count {
353
+ // This is a list of pending sidechain proposals from /our/ wallet, fetched from
354
+ // the DB.
346
355
let sidechain_proposals = self . get_our_sidechain_proposals ( ) . into_diagnostic ( ) ?;
347
356
let mut coinbase_builder = CoinbaseBuilder :: new ( ) ;
348
357
for sidechain_proposal in sidechain_proposals {
349
358
coinbase_builder = coinbase_builder. propose_sidechain ( sidechain_proposal) ;
350
359
}
351
360
352
361
let mut sidechain_acks = self . get_sidechain_acks ( ) ?;
353
- let pending_sidechain_proposals = self . get_pending_sidechain_proposals ( ) . await ?;
362
+
363
+ // This is a map of pending sidechain proposals from the /validator/, i.e.
364
+ // proposals broadcasted by (potentially) someone else, and already active.
365
+ let active_sidechain_proposals = self . get_active_sidechain_proposals ( ) . await ?;
354
366
355
367
if ack_all_proposals {
356
368
tracing:: info!(
357
369
"Handle sidechain ACK: acking all sidechains irregardless of what DB says"
358
370
) ;
359
371
360
372
let acks = sidechain_acks. clone ( ) ;
361
- for ( sidechain_number, sidechain_proposal) in & pending_sidechain_proposals {
373
+ for ( sidechain_number, sidechain_proposal) in & active_sidechain_proposals {
362
374
let sidechain_number = * sidechain_number;
363
375
364
376
if !acks
@@ -384,7 +396,7 @@ impl Wallet {
384
396
}
385
397
386
398
for sidechain_ack in sidechain_acks {
387
- if !self . validate_sidechain_ack ( & sidechain_ack, & pending_sidechain_proposals ) {
399
+ if !self . validate_sidechain_ack ( & sidechain_ack, & active_sidechain_proposals ) {
388
400
self . delete_sidechain_ack ( & sidechain_ack) ?;
389
401
tracing:: info!(
390
402
"Unable to handle sidechain ack, deleted: {}" ,
@@ -428,13 +440,13 @@ impl Wallet {
428
440
) ;
429
441
430
442
self . mine ( & coinbase_outputs, deposit_transactions) . await ?;
431
- self . delete_sidechain_proposals ( ) ?;
432
- self . delete_deposits ( ) ?;
443
+ self . delete_pending_sidechain_proposals ( ) ?;
444
+ self . delete_pending_deposits ( ) ?;
433
445
}
434
446
Ok ( ( ) )
435
447
}
436
448
437
- pub fn delete_deposits ( & self ) -> Result < ( ) > {
449
+ fn delete_pending_deposits ( & self ) -> Result < ( ) > {
438
450
self . db_connection
439
451
. lock ( )
440
452
. execute ( "DELETE FROM deposits;" , ( ) )
@@ -444,7 +456,7 @@ impl Wallet {
444
456
445
457
/// Fetches pending deposits. If `sidechain_number` is provided, only
446
458
/// deposits for that sidechain are returned.
447
- pub fn get_pending_deposits (
459
+ fn get_pending_deposits (
448
460
& self ,
449
461
sidechain_number : Option < SidechainNumber > ,
450
462
) -> Result < Vec < Deposit > > {
@@ -498,7 +510,7 @@ impl Wallet {
498
510
with_connection ( & self . db_connection . lock ( ) )
499
511
}
500
512
501
- pub fn get_bmm_requests ( & self ) -> Result < Vec < ( SidechainNumber , [ u8 ; 32 ] ) > > {
513
+ fn get_bmm_requests ( & self ) -> Result < Vec < ( SidechainNumber , [ u8 ; 32 ] ) > > {
502
514
// Satisfy clippy with a single function call per lock
503
515
let with_connection = |connection : & Connection | -> Result < _ , _ > {
504
516
let mut statement = connection
@@ -587,7 +599,7 @@ impl Wallet {
587
599
Ok ( ( ) )
588
600
}
589
601
590
- pub fn get_utxos ( & self ) -> Result < ( ) > {
602
+ fn get_utxos ( & self ) -> Result < ( ) > {
591
603
if self . last_sync . read ( ) . is_none ( ) {
592
604
return Err ( miette ! ( "get utxos: wallet not synced" ) ) ;
593
605
}
@@ -607,6 +619,9 @@ impl Wallet {
607
619
Ok ( ( ) )
608
620
}
609
621
622
+ /// Persists a sidechain proposal into our database.
623
+ /// On regtest: picked up by the next block generation.
624
+ /// On signet: TBD, but needs some way of getting communicated to the miner.
610
625
pub fn propose_sidechain ( & self , proposal : & SidechainProposal ) -> Result < ( ) , rusqlite:: Error > {
611
626
let sidechain_number: u8 = proposal. sidechain_number . into ( ) ;
612
627
self . db_connection . lock ( ) . execute (
@@ -644,7 +659,7 @@ impl Wallet {
644
659
Ok ( ( ) )
645
660
}
646
661
647
- pub fn get_sidechain_acks ( & self ) -> Result < Vec < SidechainAck > > {
662
+ fn get_sidechain_acks ( & self ) -> Result < Vec < SidechainAck > > {
648
663
// Satisfy clippy with a single function call per lock
649
664
let with_connection = |connection : & Connection | -> Result < _ > {
650
665
let mut statement = connection
@@ -666,7 +681,7 @@ impl Wallet {
666
681
with_connection ( & self . db_connection . lock ( ) )
667
682
}
668
683
669
- pub fn delete_sidechain_ack ( & self , ack : & SidechainAck ) -> Result < ( ) > {
684
+ fn delete_sidechain_ack ( & self , ack : & SidechainAck ) -> Result < ( ) > {
670
685
self . db_connection
671
686
. lock ( )
672
687
. execute (
@@ -677,13 +692,14 @@ impl Wallet {
677
692
Ok ( ( ) )
678
693
}
679
694
680
- pub async fn get_pending_sidechain_proposals (
695
+ /// Fetches sidechain proposals from the validator. Returns proposals that
696
+ /// are already included into a block, and possible to vote on.
697
+ async fn get_active_sidechain_proposals (
681
698
& self ,
682
699
) -> Result < HashMap < SidechainNumber , SidechainProposal > > {
683
700
let pending_proposals = self
684
701
. validator
685
- . get_sidechains ( )
686
- . map_err ( |e| miette:: miette!( e. to_string( ) ) ) ?
702
+ . get_sidechains ( ) ?
687
703
. into_iter ( )
688
704
. map ( |( _, sidechain) | ( sidechain. proposal . sidechain_number , sidechain. proposal ) )
689
705
. collect ( ) ;
@@ -714,11 +730,7 @@ impl Wallet {
714
730
with_connection ( & self . db_connection . lock ( ) )
715
731
}
716
732
717
- pub fn get_mainchain_tip ( & self ) -> Result < bitcoin:: BlockHash > {
718
- self . validator . get_mainchain_tip ( )
719
- }
720
-
721
- pub async fn get_sidechain_ctip (
733
+ async fn get_sidechain_ctip (
722
734
& self ,
723
735
sidechain_number : SidechainNumber ,
724
736
) -> Result < Option < ( bitcoin:: OutPoint , Amount , u64 ) > > {
@@ -737,7 +749,9 @@ impl Wallet {
737
749
}
738
750
}
739
751
740
- pub fn delete_sidechain_proposals ( & self ) -> Result < ( ) > {
752
+ // Gets wiped upon generating a new block.
753
+ // TODO: how will this work for non-regtest?
754
+ fn delete_pending_sidechain_proposals ( & self ) -> Result < ( ) > {
741
755
self . db_connection
742
756
. lock ( )
743
757
. execute ( "DELETE FROM sidechain_proposals;" , ( ) )
@@ -747,12 +761,11 @@ impl Wallet {
747
761
748
762
pub fn is_sidechain_active ( & self , sidechain_number : SidechainNumber ) -> Result < bool > {
749
763
let sidechains = self . validator . get_active_sidechains ( ) ?;
750
- for sidechain in sidechains {
751
- if sidechain. proposal . sidechain_number == sidechain_number {
752
- return Ok ( true ) ;
753
- }
754
- }
755
- Ok ( false )
764
+ let active = sidechains
765
+ . iter ( )
766
+ . any ( |sc| sc. proposal . sidechain_number == sidechain_number) ;
767
+
768
+ Ok ( active)
756
769
}
757
770
758
771
// Creates a BMM request transaction. Does NOT broadcast. `height` is the block height this
0 commit comments