-
Notifications
You must be signed in to change notification settings - Fork 211
/
reward.go
37 lines (32 loc) · 1013 Bytes
/
reward.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package mesh
import (
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/log"
"math"
"math/big"
)
// Config defines the configuration options for Spacemesh rewards.
type Config struct {
BaseReward *big.Int `mapstructure:"base-reward"`
}
// DefaultMeshConfig returns the default Config.
func DefaultMeshConfig() Config {
return Config{
BaseReward: big.NewInt(50 * int64(math.Pow10(12))),
}
}
func calculateLayerReward(id types.LayerID, params Config) *big.Int {
// todo: add inflation rules here
return params.BaseReward
}
func calculateActualRewards(layer types.LayerID, rewards *big.Int, numBlocks *big.Int) *big.Int {
div, mod := new(big.Int).DivMod(rewards, numBlocks, new(big.Int))
log.With().Info("Reward calculated",
log.LayerID(uint64(layer)),
log.Uint64("total_reward", rewards.Uint64()),
log.Uint64("num_blocks", numBlocks.Uint64()),
log.Uint64("block_reward", div.Uint64()),
log.Uint64("reward_remainder", mod.Uint64()),
)
return div
}