Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit faefe98

Browse files
committed
GH-29: RunTheNumbers on startup
1 parent 7434ec0 commit faefe98

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

bus/infrastructure.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"sync"
77
"time"
88

9+
"github.com/btcsuite/btcutil"
10+
911
"github.com/btcsuite/btcd/chaincfg/chainhash"
1012

1113
"github.com/ledgerhq/satstack/config"
@@ -336,3 +338,47 @@ func (b *Bus) descriptors(account config.Account) ([]descriptor, error) {
336338

337339
return ret, nil
338340
}
341+
342+
// RunTheNumbers performs inflation checks against the connected full node.
343+
//
344+
// It does NOT perform any equality comparison between expected and actual
345+
// supply.
346+
func (b *Bus) RunTheNumbers() error {
347+
client := b.getClient()
348+
defer b.recycleClient(client)
349+
350+
log.Info("Running inflation checks")
351+
352+
info, err := client.GetTxOutSetInfo()
353+
if err != nil {
354+
return err
355+
}
356+
357+
const halvingBlocks = 210000
358+
359+
var (
360+
subsidy float64 = 50
361+
supply float64 = 0
362+
)
363+
364+
i := int64(0)
365+
for ; i < info.Height/halvingBlocks; i++ {
366+
supply += halvingBlocks * subsidy
367+
subsidy /= 2
368+
}
369+
370+
supply += subsidy * float64(info.Height-(halvingBlocks*i))
371+
372+
supplyBTC, err := btcutil.NewAmount(supply)
373+
if err != nil {
374+
return err
375+
}
376+
377+
log.WithFields(log.Fields{
378+
"height": info.Height,
379+
"expectedSupply": supplyBTC,
380+
"actualSupply": info.TotalAmount,
381+
}).Info("#RunTheNumbers OK️")
382+
383+
return nil
384+
}

cmd/lss.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ func main() {
6868

6969
b.Status = bus.PendingScan
7070

71+
if err := b.RunTheNumbers(); err != nil {
72+
log.WithFields(log.Fields{
73+
"error": err,
74+
}).Fatal("Inflation checks failed")
75+
}
76+
7177
// Skip import of descriptors, if no account config found. SatStack
7278
// will run in zero-configuration mode.
7379
if configuration.Accounts == nil {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ require (
1919
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
2020
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
2121
)
22+
23+
replace github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67 => github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
22
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
3-
github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67 h1:Dl9SKb/DS8dGvQgpCCgBXbgE05OAsl8fqMgBFwsI2wo=
4-
github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94=
53
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
64
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
75
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
@@ -83,6 +81,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
8381
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
8482
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
8583
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
84+
github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0 h1:0LJRBFvQaMFjoa6iADdYLrq6SzeyqCp+RTmhy6zuqJU=
85+
github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94=
8686
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
8787
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
8888
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)