Skip to content

Commit

Permalink
blockreward: include supply in Subsidy schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 5, 2024
1 parent e14831e commit 02b47fa
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 69 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func SubsidyScheduleWithConfig(subsidyInterval int64, initialSubsidy int64, halv

for i := int64(0); i < halvingLimit; i++ {
subsidy := SubsidyAtHeightWithConfig(height, subsidyInterval, initialSubsidy, halvingLimit)
supply := SupplyAtHeightWithConfig(height, subsidyInterval, initialSubsidy, halvingLimit)
schedule = append(schedule, Subsidy{
Height: height,
Subsidy: subsidy,
Supply: supply,
})
if subsidy == 0 {
break
Expand Down
138 changes: 69 additions & 69 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,80 +105,80 @@ func TestSubsidySchedule(t *testing.T) {
{
BitcoinMainnet,
[]Subsidy{
{0, 5000000000},
{210000, 2500000000},
{420000, 1250000000},
{630000, 625000000},
{840000, 312500000},
{1050000, 156250000},
{1260000, 78125000},
{1470000, 39062500},
{1680000, 19531250},
{1890000, 9765625},
{2100000, 4882812},
{2310000, 2441406},
{2520000, 1220703},
{2730000, 610351},
{2940000, 305175},
{3150000, 152587},
{3360000, 76293},
{3570000, 38146},
{3780000, 19073},
{3990000, 9536},
{4200000, 4768},
{4410000, 2384},
{4620000, 1192},
{4830000, 596},
{5040000, 298},
{5250000, 149},
{5460000, 74},
{5670000, 37},
{5880000, 18},
{6090000, 9},
{6300000, 4},
{6510000, 2},
{6720000, 1},
{6930000, 0},
{0, 5000000000, 5000000000},
{210000, 2500000000, 1050002500000000},
{420000, 1250000000, 1575001250000000},
{630000, 625000000, 1837500625000000},
{840000, 312500000, 1968750312500000},
{1050000, 156250000, 2034375156250000},
{1260000, 78125000, 2067187578125000},
{1470000, 39062500, 2083593789062500},
{1680000, 19531250, 2091796894531250},
{1890000, 9765625, 2095898447265625},
{2100000, 4882812, 2097949223632812},
{2310000, 2441406, 2098974611711406},
{2520000, 1220703, 2099487305750703},
{2730000, 610351, 2099743652770351},
{2940000, 305175, 2099871826175175},
{3150000, 152587, 2099935912772587},
{3360000, 76293, 2099967955966293},
{3570000, 38146, 2099983977458146},
{3780000, 19073, 2099991988099073},
{3990000, 9536, 2099995993419536},
{4200000, 4768, 2099997995974768},
{4410000, 2384, 2099998997252384},
{4620000, 1192, 2099999497891192},
{4830000, 596, 2099999748210596},
{5040000, 298, 2099999873370298},
{5250000, 149, 2099999935950149},
{5460000, 74, 2099999967240074},
{5670000, 37, 2099999982780037},
{5880000, 18, 2099999990550018},
{6090000, 9, 2099999994330009},
{6300000, 4, 2099999996220004},
{6510000, 2, 2099999997060002},
{6720000, 1, 2099999997480001},
{6930000, 0, 2099999997690000},
},
},
// Litecoin Mainnet tests
{
LitecoinMainnet,
[]Subsidy{
{0, 5000000000},
{840000, 2500000000},
{1680000, 1250000000},
{2520000, 625000000},
{3360000, 312500000},
{4200000, 156250000},
{5040000, 78125000},
{5880000, 39062500},
{6720000, 19531250},
{7560000, 9765625},
{8400000, 4882812},
{9240000, 2441406},
{10080000, 1220703},
{10920000, 610351},
{11760000, 305175},
{12600000, 152587},
{13440000, 76293},
{14280000, 38146},
{15120000, 19073},
{15960000, 9536},
{16800000, 4768},
{17640000, 2384},
{18480000, 1192},
{19320000, 596},
{20160000, 298},
{21000000, 149},
{21840000, 74},
{22680000, 37},
{23520000, 18},
{24360000, 9},
{25200000, 4},
{26040000, 2},
{26880000, 1},
{27720000, 0},
{0, 5000000000, 5000000000},
{840000, 2500000000, 4200002500000000},
{1680000, 1250000000, 6300001250000000},
{2520000, 625000000, 7350000625000000},
{3360000, 312500000, 7875000312500000},
{4200000, 156250000, 8137500156250000},
{5040000, 78125000, 8268750078125000},
{5880000, 39062500, 8334375039062500},
{6720000, 19531250, 8367187519531250},
{7560000, 9765625, 8383593759765625},
{8400000, 4882812, 8391796879882812},
{9240000, 2441406, 8395898439521406},
{10080000, 1220703, 8397949219340703},
{10920000, 610351, 8398974609250351},
{11760000, 305175, 8399487303785175},
{12600000, 152587, 8399743650632587},
{13440000, 76293, 8399871823636293},
{14280000, 38146, 8399935909718146},
{15120000, 19073, 8399967952339073},
{15960000, 9536, 8399983973649536},
{16800000, 4768, 8399991983884768},
{17640000, 2384, 8399995989002384},
{18480000, 1192, 8399997991561192},
{19320000, 596, 8399998992840596},
{20160000, 298, 8399999493480298},
{21000000, 149, 8399999743800149},
{21840000, 74, 8399999868960074},
{22680000, 37, 8399999931120037},
{23520000, 18, 8399999962200018},
{24360000, 9, 8399999977320009},
{25200000, 4, 8399999984880004},
{26040000, 2, 8399999988240002},
{26880000, 1, 8399999989920001},
{27720000, 0, 8399999990760000},
},
},
}
Expand All @@ -192,7 +192,7 @@ func TestSubsidySchedule(t *testing.T) {

for i, subsidy := range subsidies {
if subsidy != test.want[i] {
t.Errorf("SubsidySchedule(%v) = %v, want %v", test.network, subsidies, test.want)
t.Errorf("SubsidySchedule(%v) = %v, want %v", test.network, subsidy, test.want[i])
break
}
}
Expand Down
1 change: 1 addition & 0 deletions subsidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package blockreward
type Subsidy struct {
Height int64
Subsidy int64
Supply int64
}

0 comments on commit 02b47fa

Please sign in to comment.