Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions cmd/node/config/economics.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@

[RewardsSettings]
[[RewardsSettings.RewardsConfigByEpoch]]
EpochEnable = 0
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
ProtocolSustainabilityAddress = "erd1j25xk97yf820rgdp3mj5scavhjkn6tjyn0t63pmv5qyjj7wxlcfqqe2rw5"
TopUpGradientPoint = "3000000000000000000000000" # 3MIL eGLD (eligible topUp)
TopUpFactor = 0.25 # fraction of value 0.25 - 25%
EpochEnable = 0
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
ProtocolSustainabilityAddress = "erd1j25xk97yf820rgdp3mj5scavhjkn6tjyn0t63pmv5qyjj7wxlcfqqe2rw5"
TopUpGradientPoint = "3000000000000000000000000" # 3MIL eGLD (eligible topUp)
TopUpFactor = 0.25 # fraction of value 0.25 - 25%

[[RewardsSettings.RewardsConfigByEpoch]]
EpochEnable = 1
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
ProtocolSustainabilityAddress = "erd1j25xk97yf820rgdp3mj5scavhjkn6tjyn0t63pmv5qyjj7wxlcfqqe2rw5"
TopUpGradientPoint = "2000000000000000000000000" # 2MIL eGLD (eligible topUp)
TopUpFactor = 0.5 # fraction of value 0.5 - 50%
EpochEnable = 1
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
ProtocolSustainabilityAddress = "erd1j25xk97yf820rgdp3mj5scavhjkn6tjyn0t63pmv5qyjj7wxlcfqqe2rw5"
TopUpGradientPoint = "2000000000000000000000000" # 2MIL eGLD (eligible topUp)
TopUpFactor = 0.5 # fraction of value 0.5 - 50%

[[RewardsSettings.RewardsConfigByEpoch]]
EpochEnable = 2
LeaderPercentage = 0.1 #fraction of value 0.1 - 10%
DeveloperPercentage = 0.3 #fraction of value 0.3 - 30%
ProtocolSustainabilityPercentage = 0.1 #fraction of value 0.1 - 10%
ProtocolSustainabilityAddress = "erd1e5cw5pegj9w2zfpzeq94wf3d5tp6g943xuhgnyysdwyr63rlkspqr0u05s"
TopUpGradientPoint = "2000000000000000000000000" # 2MIL eGLD (eligible topUp)
TopUpFactor = 0.5 # fraction of value 0.5 - 50%

[FeeSettings]
GasLimitSettings = [
Expand Down
2 changes: 1 addition & 1 deletion dataRetriever/factory/dataPoolFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestNewDataPoolFromConfig_BadConfigShouldErr(t *testing.T) {
}

func getGoodArgs() ArgsDataPool {
testEconomics := &economicsmocks.EconomicsHandlerStub{
testEconomics := &economicsmocks.EconomicsHandlerMock{
MinGasPriceCalled: func() uint64 {
return 200000000000
},
Expand Down
2 changes: 1 addition & 1 deletion epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func createMockEpochStartBootstrapArgs(
},
Requesters: generalCfg.Requesters,
},
EconomicsData: &economicsmocks.EconomicsHandlerStub{
EconomicsData: &economicsmocks.EconomicsHandlerMock{
MinGasPriceCalled: func() uint64 {
return 1
},
Expand Down
4 changes: 2 additions & 2 deletions epochStart/bootstrap/storageProcess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestStorageEpochStartBootstrap_BootstrapFromGenesis(t *testing.T) {
roundDuration := uint64(60000)
coreComp, cryptoComp := createComponentsForEpochStart()
args := createMockStorageEpochStartBootstrapArgs(coreComp, cryptoComp)
args.EconomicsData = &economicsmocks.EconomicsHandlerStub{
args.EconomicsData = &economicsmocks.EconomicsHandlerMock{
MinGasPriceCalled: func() uint64 {
return 1
},
Expand All @@ -112,7 +112,7 @@ func TestStorageEpochStartBootstrap_BootstrapMetablockNotFound(t *testing.T) {
roundDuration := uint64(6000)
coreComp, cryptoComp := createComponentsForEpochStart()
args := createMockStorageEpochStartBootstrapArgs(coreComp, cryptoComp)
args.EconomicsData = &economicsmocks.EconomicsHandlerStub{
args.EconomicsData = &economicsmocks.EconomicsHandlerMock{
MinGasPriceCalled: func() uint64 {
return 1
},
Expand Down
2 changes: 1 addition & 1 deletion epochStart/bootstrap/syncEpochStartMeta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func getEpochStartSyncerArgs() ArgsNewEpochStartMetaSyncer {
RequestHandler: &testscommon.RequestHandlerStub{},
Messenger: &p2pmocks.MessengerStub{},
ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2),
EconomicsData: &economicsmocks.EconomicsHandlerStub{},
EconomicsData: &economicsmocks.EconomicsHandlerMock{},
WhitelistHandler: &testscommon.WhiteListHandlerStub{},
StartInEpochConfig: config.EpochStartConfig{
MinNumConnectedPeersToStart: 2,
Expand Down
6 changes: 0 additions & 6 deletions epochStart/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ var ErrNilHeaderValidator = errors.New("nil header validator")
// ErrNilDataPoolsHolder signals that nil data pools holder has been provided
var ErrNilDataPoolsHolder = errors.New("nil data pools holder")

// ErrNilProtocolSustainabilityAddress signals that a nil protocol sustainability address was provided
var ErrNilProtocolSustainabilityAddress = errors.New("nil protocol sustainability address")

// ErrNilStorageService signals that a nil storage service has been provided
var ErrNilStorageService = errors.New("nil storage service")

Expand Down Expand Up @@ -203,9 +200,6 @@ var ErrNotEnoughNumOfPeersToConsiderBlockValid = errors.New("not enough num of p
// ErrNilArgumentsParser signals that nil arguments parser was provided
var ErrNilArgumentsParser = errors.New("nil arguments parsers")

// ErrProtocolSustainabilityAddressInMetachain signals that protocol sustainability address is in metachain which is not allowed
var ErrProtocolSustainabilityAddressInMetachain = errors.New("protocol sustainability address in metachain")

// ErrNilGenesisTotalSupply signals that nil genesis total supply has been provided
var ErrNilGenesisTotalSupply = errors.New("nil genesis total supply")

Expand Down
52 changes: 21 additions & 31 deletions epochStart/metachain/baseRewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ import (

// BaseRewardsCreatorArgs defines the arguments structure needed to create a base rewards creator
type BaseRewardsCreatorArgs struct {
ShardCoordinator sharding.Coordinator
PubkeyConverter core.PubkeyConverter
RewardsStorage storage.Storer
MiniBlockStorage storage.Storer
Hasher hashing.Hasher
Marshalizer marshal.Marshalizer
DataPool dataRetriever.PoolsHolder
ProtocolSustainabilityAddress string
NodesConfigProvider epochStart.NodesConfigProvider
UserAccountsDB state.AccountsAdapter
EnableEpochsHandler common.EnableEpochsHandler
ExecutionOrderHandler common.TxExecutionOrderHandler
ShardCoordinator sharding.Coordinator
PubkeyConverter core.PubkeyConverter
RewardsStorage storage.Storer
MiniBlockStorage storage.Storer
Hasher hashing.Hasher
Marshalizer marshal.Marshalizer
DataPool dataRetriever.PoolsHolder
NodesConfigProvider epochStart.NodesConfigProvider
UserAccountsDB state.AccountsAdapter
EnableEpochsHandler common.EnableEpochsHandler
ExecutionOrderHandler common.TxExecutionOrderHandler
RewardsHandler process.RewardsHandler
}

type baseRewardsCreator struct {
Expand All @@ -49,7 +49,6 @@ type baseRewardsCreator struct {
pubkeyConverter core.PubkeyConverter
rewardsStorage storage.Storer
miniBlockStorage storage.Storer
protocolSustainabilityAddress []byte
nodesConfigProvider epochStart.NodesConfigProvider
hasher hashing.Hasher
marshalizer marshal.Marshalizer
Expand All @@ -62,6 +61,7 @@ type baseRewardsCreator struct {
enableEpochsHandler common.EnableEpochsHandler
mutRewardsData sync.RWMutex
executionOrderHandler common.TxExecutionOrderHandler
rewardsHandler process.RewardsHandler
}

// NewBaseRewardsCreator will create a new base rewards creator instance
Expand All @@ -71,17 +71,6 @@ func NewBaseRewardsCreator(args BaseRewardsCreatorArgs) (*baseRewardsCreator, er
return nil, err
}

address, err := args.PubkeyConverter.Decode(args.ProtocolSustainabilityAddress)
if err != nil {
log.Warn("invalid protocol sustainability reward address", "err", err, "provided address", args.ProtocolSustainabilityAddress)
return nil, err
}

protocolSustainabilityShardID := args.ShardCoordinator.ComputeId(address)
if protocolSustainabilityShardID == core.MetachainShardId {
return nil, epochStart.ErrProtocolSustainabilityAddressInMetachain
}

currTxsCache := dataPool.NewCurrentBlockTransactionsPool()
brc := &baseRewardsCreator{
currTxs: currTxsCache,
Expand All @@ -92,14 +81,14 @@ func NewBaseRewardsCreator(args BaseRewardsCreatorArgs) (*baseRewardsCreator, er
marshalizer: args.Marshalizer,
miniBlockStorage: args.MiniBlockStorage,
dataPool: args.DataPool,
protocolSustainabilityAddress: address,
nodesConfigProvider: args.NodesConfigProvider,
accumulatedRewards: big.NewInt(0),
protocolSustainabilityValue: big.NewInt(0),
userAccountsDB: args.UserAccountsDB,
mapBaseRewardsPerBlockPerValidator: make(map[uint32]*big.Int),
enableEpochsHandler: args.EnableEpochsHandler,
executionOrderHandler: args.ExecutionOrderHandler,
rewardsHandler: args.RewardsHandler,
}

return brc, nil
Expand Down Expand Up @@ -299,9 +288,6 @@ func checkBaseArgs(args BaseRewardsCreatorArgs) error {
if check.IfNil(args.DataPool) {
return epochStart.ErrNilDataPoolsHolder
}
if len(args.ProtocolSustainabilityAddress) == 0 {
return epochStart.ErrNilProtocolSustainabilityAddress
}
if check.IfNil(args.NodesConfigProvider) {
return epochStart.ErrNilNodesConfigProvider
}
Expand All @@ -322,6 +308,9 @@ func checkBaseArgs(args BaseRewardsCreatorArgs) error {
if check.IfNil(args.ExecutionOrderHandler) {
return epochStart.ErrNilExecutionOrderHandler
}
if check.IfNil(args.RewardsHandler) {
return epochStart.ErrNilRewardsHandler
}

return nil
}
Expand Down Expand Up @@ -358,16 +347,17 @@ func (brc *baseRewardsCreator) createProtocolSustainabilityRewardTransaction(
computedEconomics *block.Economics,
) (*rewardTx.RewardTx, uint32, error) {

shardID := brc.shardCoordinator.ComputeId(brc.protocolSustainabilityAddress)
protocolSustainabilityAddressForEpoch := brc.rewardsHandler.ProtocolSustainabilityAddressInEpoch(metaBlock.GetEpoch())
protocolSustainabilityShardID := brc.shardCoordinator.ComputeId([]byte(protocolSustainabilityAddressForEpoch))
protocolSustainabilityRwdTx := &rewardTx.RewardTx{
Round: metaBlock.GetRound(),
Value: big.NewInt(0).Set(computedEconomics.RewardsForProtocolSustainability),
RcvAddr: brc.protocolSustainabilityAddress,
RcvAddr: []byte(protocolSustainabilityAddressForEpoch),
Epoch: metaBlock.GetEpoch(),
}

brc.accumulatedRewards.Add(brc.accumulatedRewards, protocolSustainabilityRwdTx.Value)
return protocolSustainabilityRwdTx, shardID, nil
return protocolSustainabilityRwdTx, protocolSustainabilityShardID, nil
}

func (brc *baseRewardsCreator) createRewardFromRwdInfo(
Expand Down
81 changes: 35 additions & 46 deletions epochStart/metachain/baseRewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metachain

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"math/big"
Expand All @@ -18,7 +17,6 @@ import (
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/testscommon"
txExecOrderStub "github.com/multiversx/mx-chain-go/testscommon/common"
Expand Down Expand Up @@ -106,28 +104,6 @@ func TestBaseRewardsCreator_NilMarshalizer(t *testing.T) {
assert.Equal(t, epochStart.ErrNilMarshalizer, err)
}

func TestBaseRewardsCreator_EmptyProtocolSustainabilityAddress(t *testing.T) {
t.Parallel()

args := getBaseRewardsArguments()
args.ProtocolSustainabilityAddress = ""

rwd, err := NewBaseRewardsCreator(args)
assert.True(t, check.IfNil(rwd))
assert.Equal(t, epochStart.ErrNilProtocolSustainabilityAddress, err)
}

func TestBaseRewardsCreator_InvalidProtocolSustainabilityAddress(t *testing.T) {
t.Parallel()

args := getBaseRewardsArguments()
args.ProtocolSustainabilityAddress = "xyz" // not a hex string

rwd, err := NewBaseRewardsCreator(args)
assert.True(t, check.IfNil(rwd))
assert.NotNil(t, err)
}

func TestBaseRewardsCreator_NilDataPoolHolder(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -176,6 +152,18 @@ func TestBaseRewardsCreator_NilEnableEpochsHandler(t *testing.T) {
assert.Equal(t, epochStart.ErrNilEnableEpochsHandler, err)
}

func TestBaseRewardsCreator_NilRewardsHandler(t *testing.T) {
t.Parallel()

args := getBaseRewardsArguments()
args.RewardsHandler = nil

rwd, err := NewBaseRewardsCreator(args)

assert.True(t, check.IfNil(rwd))
assert.Equal(t, epochStart.ErrNilRewardsHandler, err)
}

func TestBaseRewardsCreator_InvalidEnableEpochsHandler(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -210,19 +198,6 @@ func TestBaseRewardsCreator_clean(t *testing.T) {
require.NotNil(t, err)
}

func TestBaseRewardsCreator_ProtocolSustainabilityAddressInMetachainShouldErr(t *testing.T) {
t.Parallel()

args := getBaseRewardsArguments()
args.ShardCoordinator, _ = sharding.NewMultiShardCoordinator(2, 0)
// wrong configuration of staking system SC address (in metachain) as protocol sustainability address
args.ProtocolSustainabilityAddress = hex.EncodeToString([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255})

rwd, err := NewBaseRewardsCreator(args)
assert.True(t, check.IfNil(rwd))
assert.Equal(t, epochStart.ErrProtocolSustainabilityAddressInMetachain, err)
}

func TestBaseRewardsCreator_OkValsShouldWork(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -266,7 +241,7 @@ func TestBaseRewardsCreator_addProtocolRewardToMiniblocks(t *testing.T) {
require.NotNil(t, rwd)

initialProtRewardValue := big.NewInt(-100)
protRwAddr, _ := args.PubkeyConverter.Decode(args.ProtocolSustainabilityAddress)
protRwAddr, _ := args.PubkeyConverter.Decode(args.RewardsHandler.ProtocolSustainabilityAddressInEpoch(0))
protRwTx := &rewardTx.RewardTx{
Round: 100,
Value: big.NewInt(0).Set(initialProtRewardValue),
Expand Down Expand Up @@ -1190,15 +1165,28 @@ func getBaseRewardsArguments() BaseRewardsCreatorArgs {
return 0
}

rewardsTopUpGradientPoint, _ := big.NewInt(0).SetString("3000000000000000000000000", 10)

rewardsHandler := &mock.RewardsHandlerStub{
RewardsTopUpGradientPointInEpochCalled: func(_ uint32) *big.Int {
return rewardsTopUpGradientPoint
},
RewardsTopUpFactorInEpochCalled: func(_ uint32) float64 {
return 0.25
},
ProtocolSustainabilityAddressInEpochCalled: func(_ uint32) string {
return "11"
},
}

return BaseRewardsCreatorArgs{
ShardCoordinator: shardCoordinator,
PubkeyConverter: testscommon.NewPubkeyConverterMock(32),
RewardsStorage: mock.NewStorerMock(),
MiniBlockStorage: mock.NewStorerMock(),
Hasher: &hashingMocks.HasherMock{},
Marshalizer: &mock.MarshalizerMock{},
DataPool: dataRetrieverMock.NewPoolsHolderMock(),
ProtocolSustainabilityAddress: "11", // string hex => 17 decimal
ShardCoordinator: shardCoordinator,
PubkeyConverter: testscommon.NewPubkeyConverterMock(32),
RewardsStorage: mock.NewStorerMock(),
MiniBlockStorage: mock.NewStorerMock(),
Hasher: &hashingMocks.HasherMock{},
Marshalizer: &mock.MarshalizerMock{},
DataPool: dataRetrieverMock.NewPoolsHolderMock(),
NodesConfigProvider: &shardingMocks.NodesCoordinatorStub{
ConsensusGroupSizeCalled: func(shardID uint32) int {
if shardID == core.MetachainShardId {
Expand All @@ -1210,6 +1198,7 @@ func getBaseRewardsArguments() BaseRewardsCreatorArgs {
UserAccountsDB: userAccountsDB,
EnableEpochsHandler: enableEpochsHandler,
ExecutionOrderHandler: &txExecOrderStub.TxExecutionOrderHandlerStub{},
RewardsHandler: rewardsHandler,
}
}

Expand Down
Loading