Commit cd13f09 pythcoiner
committed
1 parent 3fcbb0b commit cd13f09 Copy full SHA for cd13f09
File tree 4 files changed +24
-5
lines changed
4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ impl fmt::Display for BlockChainTip {
40
40
41
41
/// Our Bitcoin backend.
42
42
pub trait BitcoinInterface : Send {
43
+ fn genesis_block_timestamp ( & self ) -> u32 ;
44
+
43
45
fn genesis_block ( & self ) -> BlockChainTip ;
44
46
45
47
/// Get the progress of the block chain synchronization.
@@ -119,6 +121,15 @@ pub trait BitcoinInterface: Send {
119
121
}
120
122
121
123
impl BitcoinInterface for d:: BitcoinD {
124
+ fn genesis_block_timestamp ( & self ) -> u32 {
125
+ self . get_block_stats (
126
+ self . get_block_hash ( 0 )
127
+ . expect ( "Genesis block hash must always be there" ) ,
128
+ )
129
+ . expect ( "Genesis block hash must always be there" )
130
+ . time
131
+ }
132
+
122
133
fn genesis_block ( & self ) -> BlockChainTip {
123
134
let height = 0 ;
124
135
let hash = self
@@ -370,6 +381,10 @@ impl BitcoinInterface for d::BitcoinD {
370
381
371
382
// FIXME: do we need to repeat the entire trait implemenation? Isn't there a nicer way?
372
383
impl BitcoinInterface for sync:: Arc < sync:: Mutex < dyn BitcoinInterface + ' static > > {
384
+ fn genesis_block_timestamp ( & self ) -> u32 {
385
+ self . lock ( ) . unwrap ( ) . genesis_block_timestamp ( )
386
+ }
387
+
373
388
fn genesis_block ( & self ) -> BlockChainTip {
374
389
self . lock ( ) . unwrap ( ) . genesis_block ( )
375
390
}
Original file line number Diff line number Diff line change @@ -33,9 +33,6 @@ use miniscript::{
33
33
} ;
34
34
use serde:: { Deserialize , Serialize } ;
35
35
36
- // Timestamp in the header of the genesis block. Used for sanity checks.
37
- const MAINNET_GENESIS_TIME : u32 = 1231006505 ;
38
-
39
36
#[ derive( Debug , Clone , PartialEq , Eq ) ]
40
37
pub enum CommandError {
41
38
NoOutpointForSelfSend ,
@@ -888,13 +885,14 @@ impl DaemonControl {
888
885
/// The date must be after the genesis block time and before the current tip blocktime.
889
886
pub fn start_rescan ( & self , timestamp : u32 ) -> Result < ( ) , CommandError > {
890
887
let mut db_conn = self . db . connection ( ) ;
888
+ let genesis_timestamp = self . bitcoin . genesis_block_timestamp ( ) ;
891
889
892
890
let future_timestamp = self
893
891
. bitcoin
894
892
. tip_time ( )
895
893
. map ( |t| timestamp >= t)
896
894
. unwrap_or ( false ) ;
897
- if timestamp < MAINNET_GENESIS_TIME || future_timestamp {
895
+ if timestamp < genesis_timestamp || future_timestamp {
898
896
return Err ( CommandError :: InsaneRescanTimestamp ( timestamp) ) ;
899
897
}
900
898
if db_conn. rescan_timestamp ( ) . is_some ( ) || self . bitcoin . rescan_progress ( ) . is_some ( ) {
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ impl DummyBitcoind {
34
34
}
35
35
36
36
impl BitcoinInterface for DummyBitcoind {
37
+ fn genesis_block_timestamp ( & self ) -> u32 {
38
+ 1231006505
39
+ }
40
+
37
41
fn genesis_block ( & self ) -> BlockChainTip {
38
42
let hash = bitcoin:: BlockHash :: from_str (
39
43
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" ,
Original file line number Diff line number Diff line change @@ -599,7 +599,9 @@ def all_spent(coins):
599
599
with pytest .raises (RpcError , match = "Insane timestamp.*" ):
600
600
lianad .rpc .startrescan (future_timestamp )
601
601
assert lianad .rpc .getinfo ()["rescan_progress" ] is None
602
- prebitcoin_timestamp = 1231006505 - 1
602
+ block_hash = bitcoind .rpc .getblockhash (0 )
603
+ genesis_timestamp = bitcoind .rpc .getblock (block_hash )["time" ]
604
+ prebitcoin_timestamp = genesis_timestamp - 1
603
605
with pytest .raises (RpcError , match = "Insane timestamp." ):
604
606
lianad .rpc .startrescan (prebitcoin_timestamp )
605
607
assert lianad .rpc .getinfo ()["rescan_progress" ] is None
You can’t perform that action at this time.
0 commit comments