diff --git a/blockchain/supply.go b/blockchain/supply.go new file mode 100644 index 00000000..3dc6ea8e --- /dev/null +++ b/blockchain/supply.go @@ -0,0 +1,23 @@ +package blockchain + +import "github.com/deroproject/derohe/config" + +func CalcSupply(height uint64) uint64 { + supply := config.PREMINE + remainingBlocks := height + epochStartHeight := uint64(0) + + for remainingBlocks > 0 { + blocksInEpoch := RewardReductionInterval + if remainingBlocks < blocksInEpoch { + blocksInEpoch = remainingBlocks + } + + supply += CalcBlockReward(epochStartHeight) * blocksInEpoch + + remainingBlocks -= blocksInEpoch + epochStartHeight += RewardReductionInterval + } + + return supply +} diff --git a/cmd/derod/main.go b/cmd/derod/main.go index f8184948..f1e0efe6 100644 --- a/cmd/derod/main.go +++ b/cmd/derod/main.go @@ -145,7 +145,7 @@ func main() { if _, ok := globals.Arguments["--log-dir"]; ok && globals.Arguments["--log-dir"] != nil { logdir = globals.Arguments["--log-dir"].(string) filename = filepath.Base(exename) + ".log" - filename = filepath.Join(logdir,filename) + filename = filepath.Join(logdir, filename) } globals.InitializeLog(l.Stdout(), &lumberjack.Logger{ @@ -860,9 +860,7 @@ restart_loop: mempool_tx_count := len(chain.Mempool.Mempool_List_TX()) regpool_tx_count := len(chain.Regpool.Regpool_List_TX()) - supply := uint64(0) - - supply = (config.PREMINE + blockchain.CalcBlockReward(uint64(chain.Get_Height()))*uint64(chain.Get_Height())) // valid for few years + supply := blockchain.CalcSupply(uint64(chain.Get_Height())) hostname, _ := os.Hostname() fmt.Printf("STATUS MENU for DERO HE Node - Hostname: %s\n\n", hostname) diff --git a/cmd/derod/rpc/rpc_dero_getinfo.go b/cmd/derod/rpc/rpc_dero_getinfo.go index 4103e61f..c4bfe71a 100644 --- a/cmd/derod/rpc/rpc_dero_getinfo.go +++ b/cmd/derod/rpc/rpc_dero_getinfo.go @@ -78,8 +78,8 @@ func GetInfo(ctx context.Context) (result rpc.GetInfo_Result, err error) { //result.Dynamic_fee_per_kb = config.FEE_PER_KB //result.Median_Block_Size = config.CRYPTONOTE_MAX_BLOCK_SIZE - result.Total_Supply = (config.PREMINE + blockchain.CalcBlockReward(uint64(result.TopoHeight))*uint64(result.TopoHeight)) // valid for few years - result.Total_Supply = result.Total_Supply / 100000 // only give deros remove fractional part + result.Total_Supply = blockchain.CalcSupply(uint64(chain.Get_Height())) + result.Total_Supply = result.Total_Supply / 100000 // only give deros remove fractional part if globals.Config.Name != config.Mainnet.Name { // anything other than mainnet is testnet at this point in time result.Testnet = true