From 13a7ae07317e0f360b9d1e7c445a12a1069d61c8 Mon Sep 17 00:00:00 2001 From: Zhijie Shen <35021395+zjshen14@users.noreply.github.com> Date: Wed, 6 Feb 2019 12:44:17 -0800 Subject: [PATCH] IOTEX-248 Define the producer rewarding protocol APIs (#493) --- action/protocol/account/protocol_test.go | 2 +- action/protocol/account/transfer.go | 6 +- action/protocol/context.go | 25 +- .../protocol/execution/evm/contract_test.go | 4 +- action/protocol/execution/evm/evm.go | 10 +- action/protocol/execution/protocol.go | 2 +- action/protocol/execution/protocol_test.go | 8 +- .../mainchain/createdeposit_test.go | 2 +- .../multichain/mainchain/putblock_test.go | 2 +- .../mainchain/startsubchain_test.go | 3 +- action/protocol/rewarding/admin.go | 222 +++++ action/protocol/rewarding/admin_test.go | 108 +++ action/protocol/rewarding/claimmsg.go | 100 ++ action/protocol/rewarding/depositmsg.go | 100 ++ action/protocol/rewarding/fund.go | 120 +++ action/protocol/rewarding/fund_test.go | 51 + action/protocol/rewarding/grantrewardmsg.go | 83 ++ action/protocol/rewarding/message_test.go | 59 ++ action/protocol/rewarding/protocol.go | 195 ++++ action/protocol/rewarding/protocol_test.go | 87 ++ action/protocol/rewarding/reward.go | 276 ++++++ action/protocol/rewarding/reward_test.go | 142 +++ .../rewarding/rewardingpb/rewarding.pb.go | 212 +++++ .../rewarding/rewardingpb/rewarding.proto | 28 + action/protocol/rewarding/setrewardmsg.go | 123 +++ action/protocol/vote/protocol.go | 10 +- actpool/actpool_test.go | 12 +- blockchain/blockchain.go | 28 +- blockchain/blockchain_test.go | 6 +- blockchain/blockvalidator.go | 10 +- blockchain/blockvalidator_test.go | 2 +- consensus/scheme/rolldpos/rolldpos_test.go | 2 +- explorer/explorer_test.go | 2 +- proto/action.pb.go | 877 +++++++++++++----- proto/action.proto | 36 + proto/blockchain.pb.go | 48 +- proto/endorsement.pb.go | 14 +- proto/state.pb.go | 6 +- state/factory/factory_test.go | 8 +- state/factory/statetx.go | 14 + state/factory/workingset.go | 14 + 41 files changed, 2727 insertions(+), 332 deletions(-) create mode 100644 action/protocol/rewarding/admin.go create mode 100644 action/protocol/rewarding/admin_test.go create mode 100644 action/protocol/rewarding/claimmsg.go create mode 100644 action/protocol/rewarding/depositmsg.go create mode 100644 action/protocol/rewarding/fund.go create mode 100644 action/protocol/rewarding/fund_test.go create mode 100644 action/protocol/rewarding/grantrewardmsg.go create mode 100644 action/protocol/rewarding/message_test.go create mode 100644 action/protocol/rewarding/protocol.go create mode 100644 action/protocol/rewarding/protocol_test.go create mode 100644 action/protocol/rewarding/reward.go create mode 100644 action/protocol/rewarding/reward_test.go create mode 100644 action/protocol/rewarding/rewardingpb/rewarding.pb.go create mode 100644 action/protocol/rewarding/rewardingpb/rewarding.proto create mode 100644 action/protocol/rewarding/setrewardmsg.go diff --git a/action/protocol/account/protocol_test.go b/action/protocol/account/protocol_test.go index 921e059b2d..5ed37638b9 100644 --- a/action/protocol/account/protocol_test.go +++ b/action/protocol/account/protocol_test.go @@ -45,7 +45,7 @@ func TestLoadOrCreateAccountState(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/account/transfer.go b/action/protocol/account/transfer.go index 9bd3a33709..5872aa5a14 100644 --- a/action/protocol/account/transfer.go +++ b/action/protocol/account/transfer.go @@ -40,9 +40,9 @@ func (p *Protocol) handleTransfer(act action.Action, raCtx protocol.RunActionsCt if raCtx.EnableGasCharge { // Load or create account for producer - producer, err := LoadOrCreateAccount(sm, raCtx.ProducerAddr, big.NewInt(0)) + producer, err := LoadOrCreateAccount(sm, raCtx.Producer.Bech32(), big.NewInt(0)) if err != nil { - return errors.Wrapf(err, "failed to load or create the account of block producer %s", raCtx.ProducerAddr) + return errors.Wrapf(err, "failed to load or create the account of block producer %s", raCtx.Producer.Bech32()) } gas, err := tsf.IntrinsicGas() if err != nil { @@ -66,7 +66,7 @@ func (p *Protocol) handleTransfer(act action.Action, raCtx protocol.RunActionsCt return errors.Wrapf(err, "failed to compensate gas to producer") } // Put updated producer's state to trie - if err := StoreAccount(sm, raCtx.ProducerAddr, producer); err != nil { + if err := StoreAccount(sm, raCtx.Producer.Bech32(), producer); err != nil { return errors.Wrap(err, "failed to update pending account changes to trie") } *raCtx.GasLimit -= gas diff --git a/action/protocol/context.go b/action/protocol/context.go index 38c79fe195..7a2833bfd9 100644 --- a/action/protocol/context.go +++ b/action/protocol/context.go @@ -9,8 +9,9 @@ package protocol import ( "context" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/hash" - "github.com/iotexproject/iotex-core/pkg/keypair" ) type runActionsCtxKey struct{} @@ -19,20 +20,26 @@ type validateActionsCtxKey struct{} // RunActionsCtx provides the runactions with auxiliary information. type RunActionsCtx struct { + // EpochNumber is the epoch number + EpochNumber uint64 // height of block containing those actions BlockHeight uint64 // hash of block containing those actions BlockHash hash.Hash32B - // public key of producer who compose those actions - ProducerPubKey keypair.PublicKey // timestamp of block containing those actions BlockTimeStamp int64 - // producer who compose those actions - ProducerAddr string // gas Limit for perform those actions GasLimit *uint64 // whether disable gas charge EnableGasCharge bool + // Producer is the address of whom composes the block containing this action + Producer address.Address + // Caller is the address of whom issues this action + Caller address.Address + // ActionHash is the hash of the action with the sealed envelope + ActionHash hash.Hash32B + // Nonce is the nonce of the action + Nonce uint64 } // ValidateActionsCtx provides action validators with auxiliary information. @@ -41,6 +48,8 @@ type ValidateActionsCtx struct { BlockHeight uint64 // public key of producer who compose those actions ProducerAddr string + // Caller is the address of whom issues the action + Caller address.Address } // WithRunActionsCtx add RunActionsCtx into context. @@ -55,12 +64,12 @@ func GetRunActionsCtx(ctx context.Context) (RunActionsCtx, bool) { } // WithValidateActionsCtx add ValidateActionsCtx into context. -func WithValidateActionsCtx(ctx context.Context, va *ValidateActionsCtx) context.Context { +func WithValidateActionsCtx(ctx context.Context, va ValidateActionsCtx) context.Context { return context.WithValue(ctx, validateActionsCtxKey{}, va) } // GetValidateActionsCtx gets validateActions context -func GetValidateActionsCtx(ctx context.Context) (*ValidateActionsCtx, bool) { - va, ok := ctx.Value(validateActionsCtxKey{}).(*ValidateActionsCtx) +func GetValidateActionsCtx(ctx context.Context) (ValidateActionsCtx, bool) { + va, ok := ctx.Value(validateActionsCtxKey{}).(ValidateActionsCtx) return va, ok } diff --git a/action/protocol/execution/evm/contract_test.go b/action/protocol/execution/evm/contract_test.go index 81045c3757..fcbcde3f65 100644 --- a/action/protocol/execution/evm/contract_test.go +++ b/action/protocol/execution/evm/contract_test.go @@ -77,7 +77,7 @@ func TestCreateContract(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -181,7 +181,7 @@ func TestLoadStoreContract(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/execution/evm/evm.go b/action/protocol/execution/evm/evm.go index 4d261d4c93..3402cbeb66 100644 --- a/action/protocol/execution/evm/evm.go +++ b/action/protocol/execution/evm/evm.go @@ -20,7 +20,6 @@ import ( "github.com/iotexproject/iotex-core/address" "github.com/iotexproject/iotex-core/blockchain/genesis" "github.com/iotexproject/iotex-core/pkg/hash" - "github.com/iotexproject/iotex-core/pkg/keypair" "github.com/iotexproject/iotex-core/pkg/log" ) @@ -57,7 +56,7 @@ type Params struct { } // NewParams creates a new context for use in the EVM. -func NewParams(blkHeight uint64, producerPubKey keypair.PublicKey, blkTimeStamp int64, execution *action.Execution, stateDB *StateDBAdapter) (*Params, error) { +func NewParams(blkHeight uint64, producerAddr address.Address, blkTimeStamp int64, execution *action.Execution, stateDB *StateDBAdapter) (*Params, error) { // If we don't have an explicit author (i.e. not mining), extract from the header /* var beneficiary common.Address @@ -81,8 +80,7 @@ func NewParams(blkHeight uint64, producerPubKey keypair.PublicKey, blkTimeStamp contractAddr := common.BytesToAddress(contract.Payload()) contractAddrPointer = &contractAddr } - producerHash := keypair.HashPubKey(producerPubKey) - producer := common.BytesToAddress(producerHash[:]) + producer := common.BytesToAddress(producerAddr.Payload()) context := vm.Context{ CanTransfer: CanTransfer, Transfer: MakeTransfer, @@ -142,7 +140,7 @@ func securityDeposit(ps *Params, stateDB vm.StateDB, gasLimit *uint64) error { func ExecuteContract( blkHeight uint64, blkHash hash.Hash32B, - producerPubKey keypair.PublicKey, + producer address.Address, blkTimeStamp int64, sm protocol.StateManager, execution *action.Execution, @@ -151,7 +149,7 @@ func ExecuteContract( enableGasCharge bool, ) (*action.Receipt, error) { stateDB := NewStateDBAdapter(cm, sm, blkHeight, blkHash, execution.Hash()) - ps, err := NewParams(blkHeight, producerPubKey, blkTimeStamp, execution, stateDB) + ps, err := NewParams(blkHeight, producer, blkTimeStamp, execution, stateDB) if err != nil { return nil, err } diff --git a/action/protocol/execution/protocol.go b/action/protocol/execution/protocol.go index 26a1a490ec..2a112f9a76 100644 --- a/action/protocol/execution/protocol.go +++ b/action/protocol/execution/protocol.go @@ -39,7 +39,7 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St if !ok { return nil, errors.New("failed to get RunActionsCtx") } - receipt, err := evm.ExecuteContract(raCtx.BlockHeight, raCtx.BlockHash, raCtx.ProducerPubKey, raCtx.BlockTimeStamp, + receipt, err := evm.ExecuteContract(raCtx.BlockHeight, raCtx.BlockHash, raCtx.Producer, raCtx.BlockTimeStamp, sm, exec, p.cm, raCtx.GasLimit, raCtx.EnableGasCharge) if err != nil { diff --git a/action/protocol/execution/protocol_test.go b/action/protocol/execution/protocol_test.go index 736c61abf3..713c726ccc 100644 --- a/action/protocol/execution/protocol_test.go +++ b/action/protocol/execution/protocol_test.go @@ -145,7 +145,7 @@ func (sct *smartContractTest) prepareBlockchain( gasLimit := uint64(10000000) ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -238,7 +238,7 @@ func TestProtocol_Handle(t *testing.T) { gasLimit := testutil.TestGasLimit ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -445,7 +445,7 @@ func TestProtocol_Handle(t *testing.T) { gasLimit := testutil.TestGasLimit ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -622,7 +622,7 @@ func TestProtocol_Handle(t *testing.T) { gasLimit := uint64(10000000) ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/multichain/mainchain/createdeposit_test.go b/action/protocol/multichain/mainchain/createdeposit_test.go index 27cd39335e..0601923d94 100644 --- a/action/protocol/multichain/mainchain/createdeposit_test.go +++ b/action/protocol/multichain/mainchain/createdeposit_test.go @@ -69,7 +69,7 @@ func TestValidateDeposit(t *testing.T) { gasLimit := testutil.TestGasLimit ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/multichain/mainchain/putblock_test.go b/action/protocol/multichain/mainchain/putblock_test.go index 3e41b56111..c34cdcc350 100644 --- a/action/protocol/multichain/mainchain/putblock_test.go +++ b/action/protocol/multichain/mainchain/putblock_test.go @@ -55,7 +55,7 @@ func TestHandlePutBlock(t *testing.T) { gasLimit := testutil.TestGasLimit ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/multichain/mainchain/startsubchain_test.go b/action/protocol/multichain/mainchain/startsubchain_test.go index 0c55ebae27..10f4d69242 100644 --- a/action/protocol/multichain/mainchain/startsubchain_test.go +++ b/action/protocol/multichain/mainchain/startsubchain_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" "fmt" + "github.com/iotexproject/iotex-core/action" "github.com/iotexproject/iotex-core/action/protocol" "github.com/iotexproject/iotex-core/action/protocol/account" @@ -269,7 +270,7 @@ func TestHandleStartSubChain(t *testing.T) { gasLimit := testutil.TestGasLimit ctx = protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/action/protocol/rewarding/admin.go b/action/protocol/rewarding/admin.go new file mode 100644 index 0000000000..fd47cbabde --- /dev/null +++ b/action/protocol/rewarding/admin.go @@ -0,0 +1,222 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "bytes" + "context" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/rewarding/rewardingpb" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/log" +) + +// admin stores the admin data of the rewarding protocol +type admin struct { + admin address.Address + BlockReward *big.Int + EpochReward *big.Int +} + +// Serialize serializes admin state into bytes +func (a admin) Serialize() ([]byte, error) { + gen := rewardingpb.Admin{ + Admin: a.admin.Bytes(), + BlockReward: a.BlockReward.Bytes(), + EpochReward: a.EpochReward.Bytes(), + } + return proto.Marshal(&gen) +} + +// Deserialize deserializes bytes into admin state +func (a *admin) Deserialize(data []byte) error { + gen := rewardingpb.Admin{} + if err := proto.Unmarshal(data, &gen); err != nil { + return err + } + var err error + if a.admin, err = address.BytesToAddress(gen.Admin); err != nil { + return err + } + a.BlockReward = big.NewInt(0).SetBytes(gen.BlockReward) + a.EpochReward = big.NewInt(0).SetBytes(gen.EpochReward) + return nil +} + +// Initialize initializes the rewarding protocol by setting the original admin, block and epoch reward +func (p *Protocol) Initialize( + ctx context.Context, + sm protocol.StateManager, + blockReward *big.Int, + epochReward *big.Int, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertAmount(blockReward); err != nil { + return err + } + if err := p.assertAmount(epochReward); err != nil { + return err + } + if err := p.putState( + sm, + adminKey, + &admin{ + admin: raCtx.Caller, + BlockReward: blockReward, + EpochReward: epochReward, + }, + ); err != nil { + return err + } + if err := p.putState( + sm, + fundKey, + &fund{ + totalBalance: big.NewInt(0), + unclaimedBalance: big.NewInt(0), + }, + ); err != nil { + return err + } + return nil +} + +// Admin returns the address of current admin +func (p *Protocol) Admin( + _ context.Context, + sm protocol.StateManager, +) (address.Address, error) { + admin := admin{} + if err := p.state(sm, adminKey, &admin); err != nil { + return nil, err + } + return admin.admin, nil +} + +// SetAdmin sets a new admin address. Only the current admin could make this change +func (p *Protocol) SetAdmin( + ctx context.Context, + sm protocol.StateManager, + addr address.Address, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertAdminPermission(raCtx, sm); err != nil { + return err + } + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return err + } + a.admin = addr + if err := p.putState(sm, adminKey, &a); err != nil { + return err + } + return nil +} + +// BlockReward returns the block reward amount +func (p *Protocol) BlockReward( + _ context.Context, + sm protocol.StateManager, +) (*big.Int, error) { + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return nil, err + } + return a.BlockReward, nil +} + +// SetBlockReward sets the block reward amount for the block rewarding. Only the current admin could make this change +func (p *Protocol) SetBlockReward( + ctx context.Context, + sm protocol.StateManager, + amount *big.Int, +) error { + return p.setReward(ctx, sm, amount, true) +} + +// EpochReward returns the epoch reward amount +func (p *Protocol) EpochReward( + _ context.Context, + sm protocol.StateManager, +) (*big.Int, error) { + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return nil, err + } + return a.EpochReward, nil +} + +// SetEpochReward sets the epoch reward amount shared by all beneficiaries in an epoch. Only the current admin could +// make this change +func (p *Protocol) SetEpochReward( + ctx context.Context, + sm protocol.StateManager, + amount *big.Int, +) error { + return p.setReward(ctx, sm, amount, false) +} + +func (p *Protocol) assertAmount(amount *big.Int) error { + if amount.Cmp(big.NewInt(0)) >= 0 { + return nil + } + return errors.Errorf("reward amount %s shouldn't be negative", amount.String()) +} + +func (p *Protocol) assertAdminPermission(raCtx protocol.RunActionsCtx, sm protocol.StateManager) error { + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return err + } + if bytes.Equal(a.admin.Bytes(), raCtx.Caller.Bytes()) { + return nil + } + return errors.Errorf("%s is not the rewarding protocol admin", raCtx.Caller.Bech32()) +} + +func (p *Protocol) setReward( + ctx context.Context, + sm protocol.StateManager, + amount *big.Int, + blockLevel bool, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertAdminPermission(raCtx, sm); err != nil { + return err + } + if err := p.assertAmount(amount); err != nil { + return err + } + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return err + } + if blockLevel { + a.BlockReward = amount + } else { + a.EpochReward = amount + } + if err := p.putState(sm, adminKey, &a); err != nil { + return err + } + return nil +} diff --git a/action/protocol/rewarding/admin_test.go b/action/protocol/rewarding/admin_test.go new file mode 100644 index 0000000000..f063a672df --- /dev/null +++ b/action/protocol/rewarding/admin_test.go @@ -0,0 +1,108 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + "testing" + + "github.com/iotexproject/go-ethereum/crypto" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/keypair" + "github.com/iotexproject/iotex-core/state/factory" +) + +func TestProtocol_Admin(t *testing.T) { + testProtocol(t, func(t *testing.T, ctx context.Context, stateDB factory.Factory, p *Protocol) { + // Update block reward + ws, err := stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.SetBlockReward(ctx, ws, big.NewInt(20))) + stateDB.Commit(ws) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + blockReward, err := p.BlockReward(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(20), blockReward) + + // Set block reward again will fail because caller is not admin + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + skNoAuth, err := crypto.GenerateKey() + require.NoError(t, err) + pkHashNoAuth := keypair.HashPubKey(&skNoAuth.PublicKey) + addrNoAuth := address.New(pkHashNoAuth[:]) + require.Error(t, p.SetBlockReward( + protocol.WithRunActionsCtx( + context.Background(), + protocol.RunActionsCtx{ + Caller: addrNoAuth, + }, + ), + ws, + big.NewInt(30), + )) + + // Update epoch reward + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.SetEpochReward(ctx, ws, big.NewInt(200))) + stateDB.Commit(ws) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + epochReward, err := p.EpochReward(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(200), epochReward) + + // Set epoch reward again will fail because caller is not admin + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.SetEpochReward( + protocol.WithRunActionsCtx( + context.Background(), + protocol.RunActionsCtx{ + Caller: addrNoAuth, + }, + ), + ws, + big.NewInt(300), + )) + + // Update admin + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + skNew, err := crypto.GenerateKey() + require.NoError(t, err) + pkHashNew := keypair.HashPubKey(&skNew.PublicKey) + addrNew := address.New(pkHashNew[:]) + require.NoError(t, p.SetAdmin(ctx, ws, addrNew)) + stateDB.Commit(ws) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + adminAddr, err := p.Admin(ctx, ws) + require.NoError(t, err) + assert.Equal(t, addrNew.Bytes(), adminAddr.Bytes()) + + // Update admin again will fail because addr is no longer the admin + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + skNew, err = crypto.GenerateKey() + require.NoError(t, err) + pkHashNew = keypair.HashPubKey(&skNew.PublicKey) + addrNew = address.New(pkHashNew[:]) + require.Error(t, p.SetAdmin(ctx, ws, addrNew)) + }) + +} diff --git a/action/protocol/rewarding/claimmsg.go b/action/protocol/rewarding/claimmsg.go new file mode 100644 index 0000000000..578a0085d4 --- /dev/null +++ b/action/protocol/rewarding/claimmsg.go @@ -0,0 +1,100 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "math" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + "github.com/iotexproject/iotex-core/proto" +) + +var ( + claimFromRewardingFundBaseGas = uint64(10000) + claimFromRewardingFundGasPerByte = uint64(100) +) + +// ClaimFromRewardingFund is the action to claim reward from the rewarding fund +type ClaimFromRewardingFund struct { + action.AbstractAction + amount *big.Int + data []byte +} + +// Amount returns the amount to claim +func (c *ClaimFromRewardingFund) Amount() *big.Int { return c.amount } + +// Data returns the additional data +func (c *ClaimFromRewardingFund) Data() []byte { return c.data } + +// ByteStream returns a raw byte stream of a claim action +func (c *ClaimFromRewardingFund) ByteStream() []byte { + return byteutil.Must(proto.Marshal(c.Proto())) +} + +// Proto converts a claim action struct to a claim action protobuf +func (c *ClaimFromRewardingFund) Proto() *iproto.ClaimFromRewardingFund { + return &iproto.ClaimFromRewardingFund{ + Amount: c.amount.Bytes(), + Data: c.data, + } +} + +// LoadProto converts a claim action protobuf to a claim action struct +func (c *ClaimFromRewardingFund) LoadProto(claim *iproto.ClaimFromRewardingFund) error { + *c = ClaimFromRewardingFund{} + c.amount = big.NewInt(0).SetBytes(claim.Amount) + c.data = claim.Data + return nil +} + +// IntrinsicGas returns the intrinsic gas of a claim action +func (c *ClaimFromRewardingFund) IntrinsicGas() (uint64, error) { + dataLen := uint64(len(c.Data())) + if (math.MaxUint64-claimFromRewardingFundBaseGas)/claimFromRewardingFundGasPerByte < dataLen { + return 0, action.ErrOutOfGas + } + return claimFromRewardingFundBaseGas + claimFromRewardingFundGasPerByte*dataLen, nil +} + +// Cost returns the total cost of a claim action +func (c *ClaimFromRewardingFund) Cost() (*big.Int, error) { + intrinsicGas, err := c.IntrinsicGas() + if err != nil { + return nil, errors.Wrap(err, "error when getting intrinsic gas for the claim action") + } + return big.NewInt(0).Mul(c.GasPrice(), big.NewInt(0).SetUint64(intrinsicGas)), nil +} + +// ClaimFromRewardingFundBuilder is the struct to build ClaimFromRewardingFund +type ClaimFromRewardingFundBuilder struct { + action.Builder + claim ClaimFromRewardingFund +} + +// SetAmount sets the amount to claim +func (b *ClaimFromRewardingFundBuilder) SetAmount(amount *big.Int) *ClaimFromRewardingFundBuilder { + b.claim.amount = amount + return b +} + +// SetData sets the additional data +func (b *ClaimFromRewardingFundBuilder) SetData(data []byte) *ClaimFromRewardingFundBuilder { + b.claim.data = data + return b +} + +// Build builds a new claim from rewarding fund action +func (b *ClaimFromRewardingFundBuilder) Build() ClaimFromRewardingFund { + b.claim.AbstractAction = b.Builder.Build() + return b.claim +} diff --git a/action/protocol/rewarding/depositmsg.go b/action/protocol/rewarding/depositmsg.go new file mode 100644 index 0000000000..3d3f5e8c0f --- /dev/null +++ b/action/protocol/rewarding/depositmsg.go @@ -0,0 +1,100 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "math" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + "github.com/iotexproject/iotex-core/proto" +) + +var ( + depositToRewardingFundBaseGas = uint64(10000) + depositToRewardingFundGasPerByte = uint64(100) +) + +// DonateToRewardingFund is the action to donate to the rewarding fund +type DonateToRewardingFund struct { + action.AbstractAction + amount *big.Int + data []byte +} + +// Amount returns the amount to donate +func (d *DonateToRewardingFund) Amount() *big.Int { return d.amount } + +// Data returns the additional data +func (d *DonateToRewardingFund) Data() []byte { return d.data } + +// ByteStream returns a raw byte stream of a donate action +func (d *DonateToRewardingFund) ByteStream() []byte { + return byteutil.Must(proto.Marshal(d.Proto())) +} + +// Proto converts a donate action struct to a donate action protobuf +func (d *DonateToRewardingFund) Proto() *iproto.DepositToRewardingFund { + return &iproto.DepositToRewardingFund{ + Amount: d.amount.Bytes(), + Data: d.data, + } +} + +// LoadProto converts a donate action protobuf to a donate action struct +func (d *DonateToRewardingFund) LoadProto(donate *iproto.DepositToRewardingFund) error { + *d = DonateToRewardingFund{} + d.amount = big.NewInt(0).SetBytes(donate.Amount) + d.data = donate.Data + return nil +} + +// IntrinsicGas returns the intrinsic gas of a donate action +func (d *DonateToRewardingFund) IntrinsicGas() (uint64, error) { + dataLen := uint64(len(d.Data())) + if (math.MaxUint64-depositToRewardingFundBaseGas)/depositToRewardingFundBaseGas < dataLen { + return 0, action.ErrOutOfGas + } + return depositToRewardingFundBaseGas + depositToRewardingFundBaseGas*dataLen, nil +} + +// Cost returns the total cost of a donate action +func (d *DonateToRewardingFund) Cost() (*big.Int, error) { + intrinsicGas, err := d.IntrinsicGas() + if err != nil { + return nil, errors.Wrap(err, "error when getting intrinsic gas for the donate action") + } + return big.NewInt(0).Mul(d.GasPrice(), big.NewInt(0).SetUint64(intrinsicGas)), nil +} + +// DonateToRewardingFundBuilder is the struct to build DonateToRewardingFund +type DonateToRewardingFundBuilder struct { + action.Builder + donate DonateToRewardingFund +} + +// SetAmount sets the amount to donate +func (b *DonateToRewardingFundBuilder) SetAmount(amount *big.Int) *DonateToRewardingFundBuilder { + b.donate.amount = amount + return b +} + +// SetData sets the additional data +func (b *DonateToRewardingFundBuilder) SetData(data []byte) *DonateToRewardingFundBuilder { + b.donate.data = data + return b +} + +// Build builds a new donate to rewarding fund action +func (b *DonateToRewardingFundBuilder) Build() DonateToRewardingFund { + b.donate.AbstractAction = b.Builder.Build() + return b.donate +} diff --git a/action/protocol/rewarding/fund.go b/action/protocol/rewarding/fund.go new file mode 100644 index 0000000000..5a20fb6407 --- /dev/null +++ b/action/protocol/rewarding/fund.go @@ -0,0 +1,120 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/account" + "github.com/iotexproject/iotex-core/action/protocol/rewarding/rewardingpb" + "github.com/iotexproject/iotex-core/pkg/log" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" +) + +// fund stores the balance of the rewarding fund. The difference between total and available balance should be +// equal to the unclaimed balance in all reward accounts +type fund struct { + totalBalance *big.Int + unclaimedBalance *big.Int +} + +// Serialize serializes fund state into bytes +func (f fund) Serialize() ([]byte, error) { + gen := rewardingpb.Fund{ + TotalBalance: f.totalBalance.Bytes(), + UnclaimedBalance: f.unclaimedBalance.Bytes(), + } + return proto.Marshal(&gen) +} + +// Deserialize deserializes bytes into fund state +func (f *fund) Deserialize(data []byte) error { + gen := rewardingpb.Fund{} + if err := proto.Unmarshal(data, &gen); err != nil { + return err + } + f.totalBalance = big.NewInt(0).SetBytes(gen.TotalBalance) + f.unclaimedBalance = big.NewInt(0).SetBytes(gen.UnclaimedBalance) + return nil +} + +// Donate donates token into the rewarding fund +func (p *Protocol) Donate( + ctx context.Context, + sm protocol.StateManager, + amount *big.Int, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertEnoughBalance(raCtx, sm, amount); err != nil { + return err + } + // Subtract balance from caller + acc, err := account.LoadOrCreateAccount(sm, raCtx.Caller.Bech32(), big.NewInt(0)) + if err != nil { + return err + } + acc.Balance = big.NewInt(0).Sub(acc.Balance, amount) + account.StoreAccount(sm, raCtx.Caller.Bech32(), acc) + // Add balance to fund + f := fund{} + if err := p.state(sm, fundKey, &f); err != nil { + return err + } + f.totalBalance = big.NewInt(0).Add(f.totalBalance, amount) + f.unclaimedBalance = big.NewInt(0).Add(f.unclaimedBalance, amount) + if err := p.putState(sm, fundKey, &f); err != nil { + return err + } + return nil +} + +// TotalBalance returns the total balance of the rewarding fund +func (p *Protocol) TotalBalance( + ctx context.Context, + sm protocol.StateManager, +) (*big.Int, error) { + f := fund{} + if err := p.state(sm, fundKey, &f); err != nil { + return nil, err + } + return f.totalBalance, nil +} + +// AvailableBalance returns the available balance of the rewarding fund +func (p *Protocol) AvailableBalance( + ctx context.Context, + sm protocol.StateManager, +) (*big.Int, error) { + f := fund{} + if err := p.state(sm, fundKey, &f); err != nil { + return nil, err + } + return f.unclaimedBalance, nil +} + +func (p *Protocol) assertEnoughBalance( + raCtx protocol.RunActionsCtx, + sm protocol.StateManager, + amount *big.Int, +) error { + acc, err := account.LoadAccount(sm, byteutil.BytesTo20B(raCtx.Caller.Payload())) + if err != nil { + return err + } + if acc.Balance.Cmp(amount) < 0 { + return errors.New("balance is not enough for donation") + } + return nil +} diff --git a/action/protocol/rewarding/fund_test.go b/action/protocol/rewarding/fund_test.go new file mode 100644 index 0000000000..e3b0e0cdd4 --- /dev/null +++ b/action/protocol/rewarding/fund_test.go @@ -0,0 +1,51 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/account" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + "github.com/iotexproject/iotex-core/state/factory" +) + +func TestProtocol_Fund(t *testing.T) { + testProtocol(t, func(t *testing.T, ctx context.Context, stateDB factory.Factory, p *Protocol) { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + require.True(t, ok) + + // Donate 5 token + ws, err := stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Donate(ctx, ws, big.NewInt(5))) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + totalBalance, err := p.TotalBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(5), totalBalance) + availableBalance, err := p.AvailableBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(5), availableBalance) + acc, err := account.LoadAccount(ws, byteutil.BytesTo20B(raCtx.Caller.Payload())) + require.NoError(t, err) + assert.Equal(t, big.NewInt(995), acc.Balance) + + // Donate another 6 token will fail because + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.Donate(ctx, ws, big.NewInt(996))) + }) + +} diff --git a/action/protocol/rewarding/grantrewardmsg.go b/action/protocol/rewarding/grantrewardmsg.go new file mode 100644 index 0000000000..e5412458c0 --- /dev/null +++ b/action/protocol/rewarding/grantrewardmsg.go @@ -0,0 +1,83 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "math/big" + + "github.com/golang/protobuf/proto" + + "github.com/iotexproject/iotex-core/action" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + "github.com/iotexproject/iotex-core/proto" +) + +// GrantReward is the action to grant either block or epoch reward +type GrantReward struct { + action.AbstractAction + t int +} + +// RewardType returns the grant reward type +func (g *GrantReward) RewardType() int { return g.t } + +// ByteStream returns a raw byte stream of a grant reward action +func (g *GrantReward) ByteStream() []byte { + return byteutil.Must(proto.Marshal(g.Proto())) +} + +// Proto converts a grant reward action struct to a grant reward action protobuf +func (g *GrantReward) Proto() *iproto.GrantReward { + gProto := iproto.GrantReward{} + switch g.t { + case BlockReward: + gProto.Type = iproto.RewardType_Block + case EpochReward: + gProto.Type = iproto.RewardType_Epoch + } + return &gProto +} + +// LoadProto converts a grant reward action protobuf to a grant reward action struct +func (g *GrantReward) LoadProto(gProto *iproto.GrantReward) error { + *g = GrantReward{} + switch gProto.Type { + case iproto.RewardType_Block: + g.t = BlockReward + case iproto.RewardType_Epoch: + g.t = EpochReward + } + return nil +} + +// IntrinsicGas returns the intrinsic gas of a grant reward action, which is 0 +func (*GrantReward) IntrinsicGas() (uint64, error) { + return 0, nil +} + +// Cost returns the total cost of a grant reward action +func (*GrantReward) Cost() (*big.Int, error) { + return big.NewInt(0), nil +} + +// GrantRewardBuilder is the struct to build GrantReward +type GrantRewardBuilder struct { + action.Builder + grantReward GrantReward +} + +// SetRewardType sets the grant reward type +func (b *GrantRewardBuilder) SetRewardType(t int) *GrantRewardBuilder { + b.grantReward.t = t + return b +} + +// Build builds a new grant reward action +func (b *GrantRewardBuilder) Build() GrantReward { + b.grantReward.AbstractAction = b.Builder.Build() + return b.grantReward +} diff --git a/action/protocol/rewarding/message_test.go b/action/protocol/rewarding/message_test.go new file mode 100644 index 0000000000..2066610e62 --- /dev/null +++ b/action/protocol/rewarding/message_test.go @@ -0,0 +1,59 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disset epoch rewarded. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "math/big" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDonateToRewardingFund(t *testing.T) { + b := DonateToRewardingFundBuilder{} + s1 := b.SetAmount(big.NewInt(1)). + SetData([]byte{2}). + Build() + proto := s1.Proto() + s2 := DonateToRewardingFund{} + s2.LoadProto(proto) + assert.Equal(t, s1.Amount(), s2.Amount()) + assert.Equal(t, s2.Data(), s2.Data()) +} + +func TestClaimFromRewardingFund(t *testing.T) { + b := ClaimFromRewardingFundBuilder{} + s1 := b.SetAmount(big.NewInt(1)). + SetData([]byte{2}). + Build() + proto := s1.Proto() + s2 := ClaimFromRewardingFund{} + s2.LoadProto(proto) + assert.Equal(t, s1.Amount(), s2.Amount()) + assert.Equal(t, s2.Data(), s2.Data()) +} + +func TestSetBlockReward(t *testing.T) { + b := SetRewardBuilder{} + s1 := b.SetAmount(big.NewInt(1)). + SetData([]byte{2}). + Build() + proto := s1.Proto() + s2 := SetReward{} + s2.LoadProto(proto) + assert.Equal(t, s1.Amount(), s2.Amount()) + assert.Equal(t, s2.Data(), s2.Data()) +} + +func TestGrantBlockReward(t *testing.T) { + b := GrantRewardBuilder{} + s1 := b.SetRewardType(BlockReward).Build() + proto := s1.Proto() + s2 := GrantReward{} + s2.LoadProto(proto) + assert.Equal(t, s1.RewardType(), s2.RewardType()) +} diff --git a/action/protocol/rewarding/protocol.go b/action/protocol/rewarding/protocol.go new file mode 100644 index 0000000000..42700b99bf --- /dev/null +++ b/action/protocol/rewarding/protocol.go @@ -0,0 +1,195 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + + "github.com/iotexproject/iotex-core/action" + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/account" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/enc" + "github.com/iotexproject/iotex-core/pkg/hash" + "github.com/iotexproject/iotex-core/pkg/log" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" +) + +const ( + // BlockReward indicates that the action is to grant block reward + BlockReward = iota + // EpochReward indicates that the action is to grant epoch reward + EpochReward +) + +var ( + adminKey = []byte("admin") + fundKey = []byte("fund") + blockRewardHistoryKeyPrefix = []byte("blockRewardHistory") + epochRewardHistoryKeyPrefix = []byte("epochRewardHistory") + accountKeyPrefix = []byte("account") +) + +// Protocol defines the protocol of the rewarding fund and the rewarding process. It allows the admin to config the +// reward amount, users to donate tokens to the fund, block producers to grant them block and epoch reward and, +// beneficiaries to claim the balance into their personal account. +type Protocol struct { + addr address.Address + keyPrefix []byte +} + +// NewProtocol instantiates a rewarding protocol instance. The address of the protocol is defined by the creator's +// address and the nonce of creating it +func NewProtocol(caller address.Address, nonce uint64) *Protocol { + var nonceBytes [8]byte + enc.MachineEndian.PutUint64(nonceBytes[:], nonce) + h := hash.Hash160b(append(caller.Bytes(), nonceBytes[:]...)) + return &Protocol{ + addr: address.New(h), + keyPrefix: h, + } +} + +// Handle handles the actions on the rewarding protocol +func (p *Protocol) Handle( + ctx context.Context, + act action.Action, + sm protocol.StateManager, +) (*action.Receipt, error) { + // TODO: simplify the boilerplate + switch act := act.(type) { + case *SetReward: + switch act.RewardType() { + case BlockReward: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.SetBlockReward(ctx, sm, act.Amount()); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + case EpochReward: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.SetEpochReward(ctx, sm, act.Amount()); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + } + case *DonateToRewardingFund: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.Donate(ctx, sm, act.Amount()); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + case *ClaimFromRewardingFund: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.Claim(ctx, sm, act.Amount()); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + case *GrantReward: + switch act.RewardType() { + case BlockReward: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.GrantBlockReward(ctx, sm); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + case EpochReward: + gasConsumed, err := act.IntrinsicGas() + if err != nil { + return p.settleAction(ctx, sm, 1, 0), nil + } + if err := p.GrantEpochReward(ctx, sm); err != nil { + return p.settleAction(ctx, sm, 1, gasConsumed), nil + } + return p.settleAction(ctx, sm, 0, gasConsumed), nil + } + } + return nil, nil +} + +// Validate validates the actions on the rewarding protocol +func (p *Protocol) Validate( + ctx context.Context, + act action.Action, +) error { + // TODO: validate interface shouldn't be required for protocol code + return nil +} + +func (p *Protocol) state(sm protocol.StateManager, key []byte, value interface{}) error { + keyHash := byteutil.BytesTo20B(hash.Hash160b(append(p.keyPrefix, key...))) + return sm.State(keyHash, value) +} + +func (p *Protocol) putState(sm protocol.StateManager, key []byte, value interface{}) error { + keyHash := byteutil.BytesTo20B(hash.Hash160b(append(p.keyPrefix, key...))) + return sm.PutState(keyHash, value) +} + +func (p *Protocol) deleteState(sm protocol.StateManager, key []byte) error { + keyHash := byteutil.BytesTo20B(hash.Hash160b(append(p.keyPrefix, key...))) + return sm.DelState(keyHash) +} + +func (p *Protocol) settleAction( + ctx context.Context, + sm protocol.StateManager, + status uint64, + gasConsumed uint64, +) *action.Receipt { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.increaseNonce(sm, raCtx.Caller, raCtx.Nonce); err != nil { + return p.createReceipt(1, raCtx.ActionHash, gasConsumed) + } + return p.createReceipt(status, raCtx.ActionHash, gasConsumed) +} + +func (p *Protocol) increaseNonce(sm protocol.StateManager, addr address.Address, nonce uint64) error { + acc, err := account.LoadOrCreateAccount(sm, addr.Bech32(), big.NewInt(0)) + if err != nil { + return err + } + // TODO: this check shouldn't be necessary + if nonce > acc.Nonce { + acc.Nonce = nonce + } + if err := account.StoreAccount(sm, addr.Bech32(), acc); err != nil { + return err + } + return nil +} + +func (p *Protocol) createReceipt(status uint64, actHash hash.Hash32B, gasConsumed uint64) *action.Receipt { + // TODO: need to review the fields + return &action.Receipt{ + ReturnValue: nil, + Status: 0, + ActHash: actHash, + GasConsumed: gasConsumed, + ContractAddress: p.addr.Bech32(), + Logs: nil, + } +} diff --git a/action/protocol/rewarding/protocol_test.go b/action/protocol/rewarding/protocol_test.go new file mode 100644 index 0000000000..8c5a828067 --- /dev/null +++ b/action/protocol/rewarding/protocol_test.go @@ -0,0 +1,87 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + "testing" + + "github.com/iotexproject/iotex-core/action/protocol/account" + + "github.com/iotexproject/go-ethereum/crypto" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/config" + "github.com/iotexproject/iotex-core/pkg/keypair" + "github.com/iotexproject/iotex-core/state/factory" +) + +func testProtocol(t *testing.T, test func(*testing.T, context.Context, factory.Factory, *Protocol)) { + cfg := config.Default + stateDB, err := factory.NewStateDB(cfg, factory.InMemStateDBOption()) + require.NoError(t, err) + require.NoError(t, stateDB.Start(context.Background())) + defer require.NoError(t, stateDB.Stop(context.Background())) + + sk, err := crypto.GenerateKey() + require.NoError(t, err) + pkHash := keypair.HashPubKey(&sk.PublicKey) + addr := address.New(pkHash[:]) + + skProducer, err := crypto.GenerateKey() + require.NoError(t, err) + pkHashProducer := keypair.HashPubKey(&skProducer.PublicKey) + addrProducer := address.New(pkHashProducer[:]) + p := NewProtocol(addr, 1) + + // Initialize the protocol + ctx := protocol.WithRunActionsCtx( + context.Background(), + protocol.RunActionsCtx{ + Producer: addrProducer, + Caller: addr, + EpochNumber: 1, + BlockHeight: 1, + }, + ) + ws, err := stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Initialize(ctx, ws, big.NewInt(10), big.NewInt(100))) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + adminAddr, err := p.Admin(ctx, ws) + require.NoError(t, err) + assert.Equal(t, addr.Bytes(), adminAddr.Bytes()) + blockReward, err := p.BlockReward(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(10), blockReward) + epochReward, err := p.EpochReward(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(100), epochReward) + + totalBalance, err := p.TotalBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0), totalBalance) + availableBalance, err := p.AvailableBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0), availableBalance) + + // Create a test account with 1000 token + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + _, err = account.LoadOrCreateAccount(ws, addr.Bech32(), big.NewInt(1000)) + require.NoError(t, err) + require.NoError(t, stateDB.Commit(ws)) + + test(t, ctx, stateDB, p) +} diff --git a/action/protocol/rewarding/reward.go b/action/protocol/rewarding/reward.go new file mode 100644 index 0000000000..523164f850 --- /dev/null +++ b/action/protocol/rewarding/reward.go @@ -0,0 +1,276 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/account" + "github.com/iotexproject/iotex-core/action/protocol/rewarding/rewardingpb" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/enc" + "github.com/iotexproject/iotex-core/pkg/log" + "github.com/iotexproject/iotex-core/state" +) + +// rewardHistory is the dummy struct to record a reward. Only key matters. +type rewardHistory struct{} + +// Serialize serializes reward history state into bytes +func (b rewardHistory) Serialize() ([]byte, error) { + gen := rewardingpb.RewardHistory{} + return proto.Marshal(&gen) +} + +// Deserialize deserializes bytes into reward history state +func (b *rewardHistory) Deserialize(data []byte) error { + gen := rewardingpb.RewardHistory{} + if err := proto.Unmarshal(data, &gen); err != nil { + return err + } + return nil +} + +// rewardHistory stores the unclaimed balance of an account +type rewardAccount struct { + balance *big.Int +} + +// Serialize serializes account state into bytes +func (a rewardAccount) Serialize() ([]byte, error) { + gen := rewardingpb.Account{ + Balance: a.balance.Bytes(), + } + return proto.Marshal(&gen) +} + +// Deserialize deserializes bytes into account state +func (a *rewardAccount) Deserialize(data []byte) error { + gen := rewardingpb.Account{} + if err := proto.Unmarshal(data, &gen); err != nil { + return err + } + a.balance = big.NewInt(0).SetBytes(gen.Balance) + return nil +} + +// GrantBlockReward grants the block reward (token) to the block producer +func (p *Protocol) GrantBlockReward( + ctx context.Context, + sm protocol.StateManager, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertNoRewardYet(sm, blockRewardHistoryKeyPrefix, raCtx.BlockHeight); err != nil { + return err + } + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return err + } + if err := p.updateAvailableBalance(sm, a.BlockReward); err != nil { + return err + } + if err := p.grantToAccount(sm, raCtx.Producer, a.BlockReward); err != nil { + return err + } + if err := p.updateRewardHistory(sm, blockRewardHistoryKeyPrefix, raCtx.BlockHeight); err != nil { + return err + } + return nil +} + +// GrantEpochReward grants the epoch reward (token) to all beneficiaries of a epoch +func (p *Protocol) GrantEpochReward( + ctx context.Context, + sm protocol.StateManager, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.assertNoRewardYet(sm, epochRewardHistoryKeyPrefix, raCtx.EpochNumber); err != nil { + return err + } + // TODO: check the current block is the last block of the given epoch number + a := admin{} + if err := p.state(sm, adminKey, &a); err != nil { + return err + } + if err := p.updateAvailableBalance(sm, a.EpochReward); err != nil { + return err + } + addrs, amounts, err := p.splitEpochReward(a.EpochReward) + if err != nil { + return err + } + for i := range addrs { + if err := p.grantToAccount(sm, addrs[i], amounts[i]); err != nil { + return err + } + } + if err := p.updateRewardHistory(sm, epochRewardHistoryKeyPrefix, raCtx.EpochNumber); err != nil { + return err + } + return nil +} + +// Claim claims the token from the rewarding fund +func (p *Protocol) Claim( + ctx context.Context, + sm protocol.StateManager, + amount *big.Int, +) error { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss run action context") + } + if err := p.updateTotalBalance(sm, amount); err != nil { + return err + } + if err := p.claimFromAccount(sm, raCtx.Caller, amount); err != nil { + return err + } + return nil +} + +// UnclaimedBalance returns unclaimed balance of a given address +func (p *Protocol) UnclaimedBalance( + ctx context.Context, + sm protocol.StateManager, + addr address.Address, +) (*big.Int, error) { + acc := rewardAccount{} + accKey := append(adminKey, addr.Bytes()...) + err := p.state(sm, accKey, &acc) + if err == nil { + return acc.balance, nil + } + if errors.Cause(err) == state.ErrStateNotExist { + return big.NewInt(0), nil + } + return nil, err +} + +func (p *Protocol) updateTotalBalance(sm protocol.StateManager, amount *big.Int) error { + f := fund{} + if err := p.state(sm, fundKey, &f); err != nil { + return err + } + totalBalance := big.NewInt(0).Sub(f.totalBalance, amount) + if totalBalance.Cmp(big.NewInt(0)) < 0 { + return errors.New("no enough total balance") + } + f.totalBalance = totalBalance + if err := p.putState(sm, fundKey, &f); err != nil { + return err + } + return nil +} + +func (p *Protocol) updateAvailableBalance(sm protocol.StateManager, amount *big.Int) error { + f := fund{} + if err := p.state(sm, fundKey, &f); err != nil { + return err + } + availableBalance := big.NewInt(0).Sub(f.unclaimedBalance, amount) + if availableBalance.Cmp(big.NewInt(0)) < 0 { + return errors.New("no enough available balance") + } + f.unclaimedBalance = availableBalance + if err := p.putState(sm, fundKey, &f); err != nil { + return err + } + return nil +} + +func (p *Protocol) grantToAccount(sm protocol.StateManager, addr address.Address, amount *big.Int) error { + acc := rewardAccount{} + accKey := append(adminKey, addr.Bytes()...) + if err := p.state(sm, accKey, &acc); err != nil { + if errors.Cause(err) != state.ErrStateNotExist { + return err + } + acc = rewardAccount{ + balance: big.NewInt(0), + } + } + acc.balance = big.NewInt(0).Add(acc.balance, amount) + if err := p.putState(sm, accKey, &acc); err != nil { + return err + } + return nil +} + +func (p *Protocol) claimFromAccount(sm protocol.StateManager, addr address.Address, amount *big.Int) error { + // Update reward account + acc := rewardAccount{} + accKey := append(adminKey, addr.Bytes()...) + if err := p.state(sm, accKey, &acc); err != nil { + return err + } + balance := big.NewInt(0).Sub(acc.balance, amount) + if balance.Cmp(big.NewInt(0)) < 0 { + return errors.New("no enough available balance") + } else if balance.Cmp(big.NewInt(0)) == 0 { + // If the account balance is cleared, delete if from the store + if err := p.deleteState(sm, accKey); err != nil { + return err + } + } else { + acc.balance = balance + if err := p.putState(sm, accKey, &acc); err != nil { + return err + } + } + + // Update primary account + primAcc, err := account.LoadOrCreateAccount(sm, addr.Bech32(), big.NewInt(0)) + if err != nil { + return err + } + primAcc.Balance = big.NewInt(0).Add(primAcc.Balance, amount) + if err := account.StoreAccount(sm, addr.Bech32(), primAcc); err != nil { + + } + return nil +} + +func (p *Protocol) updateRewardHistory(sm protocol.StateManager, prefix []byte, index uint64) error { + var indexBytes [8]byte + enc.MachineEndian.PutUint64(indexBytes[:], index) + if err := p.putState(sm, append(prefix, indexBytes[:]...), &rewardHistory{}); err != nil { + return err + } + return nil +} + +func (p *Protocol) splitEpochReward(totalAmount *big.Int) ([]address.Address, []*big.Int, error) { + // TODO: implement splitting epoch reward for a set of rewarding accounts + return nil, nil, nil +} + +func (p *Protocol) assertNoRewardYet(sm protocol.StateManager, prefix []byte, index uint64) error { + history := rewardHistory{} + var indexBytes [8]byte + enc.MachineEndian.PutUint64(indexBytes[:], index) + err := p.state(sm, append(prefix, indexBytes[:]...), &history) + if err == nil { + return errors.Errorf("reward history already exists on index %d", index) + } + if errors.Cause(err) != state.ErrStateNotExist { + return err + } + return nil +} diff --git a/action/protocol/rewarding/reward_test.go b/action/protocol/rewarding/reward_test.go new file mode 100644 index 0000000000..84eeb710f7 --- /dev/null +++ b/action/protocol/rewarding/reward_test.go @@ -0,0 +1,142 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "context" + "math/big" + "testing" + + "github.com/iotexproject/iotex-core/action/protocol/account" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/state/factory" +) + +func TestProtocol_GrantReward(t *testing.T) { + testProtocol(t, func(t *testing.T, ctx context.Context, stateDB factory.Factory, p *Protocol) { + raCtx, ok := protocol.GetRunActionsCtx(ctx) + require.True(t, ok) + + // Grant block reward will fail because of no available balance + ws, err := stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.GrantBlockReward(ctx, ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Donate(ctx, ws, big.NewInt(200))) + require.NoError(t, stateDB.Commit(ws)) + + // Grant block reward + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.GrantBlockReward(ctx, ws)) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + availableBalance, err := p.AvailableBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(190), availableBalance) + unclaimedBalance, err := p.UnclaimedBalance(ctx, ws, raCtx.Producer) + require.NoError(t, err) + assert.Equal(t, big.NewInt(10), unclaimedBalance) + + // Grant the same block reward again will fail + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.GrantBlockReward(ctx, ws)) + + // Grant epoch reward + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.GrantEpochReward(ctx, ws)) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + availableBalance, err = p.AvailableBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(90), availableBalance) + unclaimedBalance, err = p.UnclaimedBalance(ctx, ws, raCtx.Producer) + require.NoError(t, err) + // TODO: assert unclaimedBalance after splitting epoch reward correctly + + // Grant the same epoch reward again will fail + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.GrantEpochReward(ctx, ws)) + }) +} + +func TestProtocol_ClaimReward(t *testing.T) { + testProtocol(t, func(t *testing.T, ctx context.Context, stateDB factory.Factory, p *Protocol) { + // Donate 20 token into the rewarding fund + ws, err := stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Donate(ctx, ws, big.NewInt(20))) + require.NoError(t, stateDB.Commit(ws)) + + // Grant block reward + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.GrantBlockReward(ctx, ws)) + require.NoError(t, stateDB.Commit(ws)) + + // Claim 5 token + raCtx, ok := protocol.GetRunActionsCtx(ctx) + require.True(t, ok) + claimRaCtx := raCtx + claimRaCtx.Caller = raCtx.Producer + claimCtx := protocol.WithRunActionsCtx(context.Background(), claimRaCtx) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Claim(claimCtx, ws, big.NewInt(5))) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + totalBalance, err := p.TotalBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(15), totalBalance) + unclaimedBalance, err := p.UnclaimedBalance(ctx, ws, raCtx.Producer) + require.NoError(t, err) + assert.Equal(t, big.NewInt(5), unclaimedBalance) + primAcc, err := account.LoadAccount(ws, byteutil.BytesTo20B(raCtx.Producer.Payload())) + require.NoError(t, err) + assert.Equal(t, big.NewInt(5), primAcc.Balance) + + // Claim another 5 token + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.NoError(t, p.Claim(claimCtx, ws, big.NewInt(5))) + require.NoError(t, stateDB.Commit(ws)) + + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + totalBalance, err = p.TotalBalance(ctx, ws) + require.NoError(t, err) + assert.Equal(t, big.NewInt(10), totalBalance) + unclaimedBalance, err = p.UnclaimedBalance(ctx, ws, raCtx.Producer) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0), unclaimedBalance) + primAcc, err = account.LoadAccount(ws, byteutil.BytesTo20B(raCtx.Producer.Payload())) + require.NoError(t, err) + assert.Equal(t, big.NewInt(10), primAcc.Balance) + + // Claim the 3-rd 5 token will fail be cause no balance for the address + ws, err = stateDB.NewWorkingSet() + require.NoError(t, err) + require.Error(t, p.Claim(claimCtx, ws, big.NewInt(5))) + }) +} diff --git a/action/protocol/rewarding/rewardingpb/rewarding.pb.go b/action/protocol/rewarding/rewardingpb/rewarding.pb.go new file mode 100644 index 0000000000..a359f8c779 --- /dev/null +++ b/action/protocol/rewarding/rewardingpb/rewarding.pb.go @@ -0,0 +1,212 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: rewarding.proto + +package rewardingpb + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type Admin struct { + Admin []byte `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` + BlockReward []byte `protobuf:"bytes,2,opt,name=blockReward,proto3" json:"blockReward,omitempty"` + EpochReward []byte `protobuf:"bytes,3,opt,name=epochReward,proto3" json:"epochReward,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Admin) Reset() { *m = Admin{} } +func (m *Admin) String() string { return proto.CompactTextString(m) } +func (*Admin) ProtoMessage() {} +func (*Admin) Descriptor() ([]byte, []int) { + return fileDescriptor_rewarding_59a21f7fb859b992, []int{0} +} +func (m *Admin) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Admin.Unmarshal(m, b) +} +func (m *Admin) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Admin.Marshal(b, m, deterministic) +} +func (dst *Admin) XXX_Merge(src proto.Message) { + xxx_messageInfo_Admin.Merge(dst, src) +} +func (m *Admin) XXX_Size() int { + return xxx_messageInfo_Admin.Size(m) +} +func (m *Admin) XXX_DiscardUnknown() { + xxx_messageInfo_Admin.DiscardUnknown(m) +} + +var xxx_messageInfo_Admin proto.InternalMessageInfo + +func (m *Admin) GetAdmin() []byte { + if m != nil { + return m.Admin + } + return nil +} + +func (m *Admin) GetBlockReward() []byte { + if m != nil { + return m.BlockReward + } + return nil +} + +func (m *Admin) GetEpochReward() []byte { + if m != nil { + return m.EpochReward + } + return nil +} + +type Fund struct { + TotalBalance []byte `protobuf:"bytes,1,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"` + UnclaimedBalance []byte `protobuf:"bytes,2,opt,name=unclaimedBalance,proto3" json:"unclaimedBalance,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Fund) Reset() { *m = Fund{} } +func (m *Fund) String() string { return proto.CompactTextString(m) } +func (*Fund) ProtoMessage() {} +func (*Fund) Descriptor() ([]byte, []int) { + return fileDescriptor_rewarding_59a21f7fb859b992, []int{1} +} +func (m *Fund) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Fund.Unmarshal(m, b) +} +func (m *Fund) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Fund.Marshal(b, m, deterministic) +} +func (dst *Fund) XXX_Merge(src proto.Message) { + xxx_messageInfo_Fund.Merge(dst, src) +} +func (m *Fund) XXX_Size() int { + return xxx_messageInfo_Fund.Size(m) +} +func (m *Fund) XXX_DiscardUnknown() { + xxx_messageInfo_Fund.DiscardUnknown(m) +} + +var xxx_messageInfo_Fund proto.InternalMessageInfo + +func (m *Fund) GetTotalBalance() []byte { + if m != nil { + return m.TotalBalance + } + return nil +} + +func (m *Fund) GetUnclaimedBalance() []byte { + if m != nil { + return m.UnclaimedBalance + } + return nil +} + +type RewardHistory struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RewardHistory) Reset() { *m = RewardHistory{} } +func (m *RewardHistory) String() string { return proto.CompactTextString(m) } +func (*RewardHistory) ProtoMessage() {} +func (*RewardHistory) Descriptor() ([]byte, []int) { + return fileDescriptor_rewarding_59a21f7fb859b992, []int{2} +} +func (m *RewardHistory) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RewardHistory.Unmarshal(m, b) +} +func (m *RewardHistory) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RewardHistory.Marshal(b, m, deterministic) +} +func (dst *RewardHistory) XXX_Merge(src proto.Message) { + xxx_messageInfo_RewardHistory.Merge(dst, src) +} +func (m *RewardHistory) XXX_Size() int { + return xxx_messageInfo_RewardHistory.Size(m) +} +func (m *RewardHistory) XXX_DiscardUnknown() { + xxx_messageInfo_RewardHistory.DiscardUnknown(m) +} + +var xxx_messageInfo_RewardHistory proto.InternalMessageInfo + +type Account struct { + Balance []byte `protobuf:"bytes,2,opt,name=balance,proto3" json:"balance,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Account) Reset() { *m = Account{} } +func (m *Account) String() string { return proto.CompactTextString(m) } +func (*Account) ProtoMessage() {} +func (*Account) Descriptor() ([]byte, []int) { + return fileDescriptor_rewarding_59a21f7fb859b992, []int{3} +} +func (m *Account) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Account.Unmarshal(m, b) +} +func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Account.Marshal(b, m, deterministic) +} +func (dst *Account) XXX_Merge(src proto.Message) { + xxx_messageInfo_Account.Merge(dst, src) +} +func (m *Account) XXX_Size() int { + return xxx_messageInfo_Account.Size(m) +} +func (m *Account) XXX_DiscardUnknown() { + xxx_messageInfo_Account.DiscardUnknown(m) +} + +var xxx_messageInfo_Account proto.InternalMessageInfo + +func (m *Account) GetBalance() []byte { + if m != nil { + return m.Balance + } + return nil +} + +func init() { + proto.RegisterType((*Admin)(nil), "rewardingpb.Admin") + proto.RegisterType((*Fund)(nil), "rewardingpb.Fund") + proto.RegisterType((*RewardHistory)(nil), "rewardingpb.RewardHistory") + proto.RegisterType((*Account)(nil), "rewardingpb.Account") +} + +func init() { proto.RegisterFile("rewarding.proto", fileDescriptor_rewarding_59a21f7fb859b992) } + +var fileDescriptor_rewarding_59a21f7fb859b992 = []byte{ + // 189 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x4a, 0x2d, 0x4f, + 0x2c, 0x4a, 0xc9, 0xcc, 0x4b, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x86, 0x0b, 0x14, + 0x24, 0x29, 0x25, 0x72, 0xb1, 0x3a, 0xa6, 0xe4, 0x66, 0xe6, 0x09, 0x89, 0x70, 0xb1, 0x26, 0x82, + 0x18, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x10, 0x8e, 0x90, 0x02, 0x17, 0x77, 0x52, 0x4e, + 0x7e, 0x72, 0x76, 0x10, 0x58, 0x8b, 0x04, 0x13, 0x58, 0x0e, 0x59, 0x08, 0xa4, 0x22, 0xb5, 0x20, + 0x3f, 0x39, 0x03, 0xaa, 0x82, 0x19, 0xa2, 0x02, 0x49, 0x48, 0x29, 0x8c, 0x8b, 0xc5, 0xad, 0x34, + 0x2f, 0x45, 0x48, 0x89, 0x8b, 0xa7, 0x24, 0xbf, 0x24, 0x31, 0xc7, 0x29, 0x31, 0x27, 0x31, 0x2f, + 0x39, 0x15, 0x6a, 0x11, 0x8a, 0x98, 0x90, 0x16, 0x97, 0x40, 0x69, 0x5e, 0x72, 0x4e, 0x62, 0x66, + 0x6e, 0x6a, 0x0a, 0x4c, 0x1d, 0xc4, 0x52, 0x0c, 0x71, 0x25, 0x7e, 0x2e, 0x5e, 0x88, 0x0d, 0x1e, + 0x99, 0xc5, 0x25, 0xf9, 0x45, 0x95, 0x4a, 0xca, 0x5c, 0xec, 0x8e, 0xc9, 0xc9, 0xf9, 0xa5, 0x79, + 0x25, 0x42, 0x12, 0x5c, 0xec, 0x49, 0x28, 0xda, 0x61, 0xdc, 0x24, 0x36, 0x70, 0x20, 0x18, 0x03, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xae, 0xbc, 0x16, 0x18, 0x17, 0x01, 0x00, 0x00, +} diff --git a/action/protocol/rewarding/rewardingpb/rewarding.proto b/action/protocol/rewarding/rewardingpb/rewarding.proto new file mode 100644 index 0000000000..1e3fa89d2b --- /dev/null +++ b/action/protocol/rewarding/rewardingpb/rewarding.proto @@ -0,0 +1,28 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +// To compile the proto, run: +// protoc --go_out=plugins=grpc:. *.proto +syntax = "proto3"; +package rewardingpb; + +message Admin { + bytes admin = 1; + bytes blockReward = 2; + bytes epochReward = 3; +} + +message Fund { + bytes totalBalance = 1; + bytes unclaimedBalance = 2; +} + +message RewardHistory { +} + +message Account { + bytes balance = 2; +} \ No newline at end of file diff --git a/action/protocol/rewarding/setrewardmsg.go b/action/protocol/rewarding/setrewardmsg.go new file mode 100644 index 0000000000..5b6ef3b688 --- /dev/null +++ b/action/protocol/rewarding/setrewardmsg.go @@ -0,0 +1,123 @@ +// Copyright (c) 2019 IoTeX +// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no +// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent +// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache +// License 2.0 that can be found in the LICENSE file. + +package rewarding + +import ( + "math" + "math/big" + + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + + "github.com/iotexproject/iotex-core/action" + "github.com/iotexproject/iotex-core/pkg/util/byteutil" + "github.com/iotexproject/iotex-core/proto" +) + +var ( + setBlockRewardBaseGas = uint64(10000) + setBlockRewardGasPerByte = uint64(100) +) + +// SetReward is the action to update the reward amount +type SetReward struct { + action.AbstractAction + amount *big.Int + data []byte + t int +} + +// Amount returns the amount to reward +func (s *SetReward) Amount() *big.Int { return s.amount } + +// Data returns the additional data +func (s *SetReward) Data() []byte { return s.data } + +// RewardType returns the grant reward type +func (s *SetReward) RewardType() int { return s.t } + +// ByteStream returns a raw byte stream of a set reward action +func (s *SetReward) ByteStream() []byte { + return byteutil.Must(proto.Marshal(s.Proto())) +} + +// Proto converts a set reward action struct to a set reward action protobuf +func (s *SetReward) Proto() *iproto.SetReward { + sProto := iproto.SetReward{ + Amount: s.amount.Bytes(), + Data: s.data, + } + switch s.t { + case BlockReward: + sProto.Type = iproto.RewardType_Block + case EpochReward: + sProto.Type = iproto.RewardType_Epoch + } + return &sProto +} + +// LoadProto converts a set block rewarding reward action protobuf to a set reward action struct +func (s *SetReward) LoadProto(sProto *iproto.SetReward) error { + *s = SetReward{} + s.amount = big.NewInt(0).SetBytes(sProto.Amount) + s.data = sProto.Data + switch sProto.Type { + case iproto.RewardType_Block: + s.t = BlockReward + case iproto.RewardType_Epoch: + s.t = EpochReward + } + return nil +} + +// IntrinsicGas returns the intrinsic gas of a set reward action +func (s *SetReward) IntrinsicGas() (uint64, error) { + dataLen := uint64(len(s.Data())) + if (math.MaxUint64-setBlockRewardBaseGas)/setBlockRewardGasPerByte < dataLen { + return 0, action.ErrOutOfGas + } + return setBlockRewardBaseGas + setBlockRewardGasPerByte*dataLen, nil +} + +// Cost returns the total cost of a set reward action +func (s *SetReward) Cost() (*big.Int, error) { + intrinsicGas, err := s.IntrinsicGas() + if err != nil { + return nil, errors.Wrap(err, "error when getting intrinsic gas for the set block reward action") + } + return big.NewInt(0).Mul(s.GasPrice(), big.NewInt(0).SetUint64(intrinsicGas)), nil +} + +// SetRewardBuilder is the struct to build SetReward +type SetRewardBuilder struct { + action.Builder + setReward SetReward +} + +// SetAmount sets the amount to reward +func (b *SetRewardBuilder) SetAmount(amount *big.Int) *SetRewardBuilder { + b.setReward.amount = amount + return b +} + +// SetData sets the additional data +func (b *SetRewardBuilder) SetData(data []byte) *SetRewardBuilder { + b.setReward.data = data + return b +} + +// SetRewardType sets the grant reward type +func (b *SetRewardBuilder) SetRewardType(t int) *SetRewardBuilder { + b.setReward.t = t + return b +} + +// Build builds a new set reward action +func (b *SetRewardBuilder) Build() SetReward { + b.setReward.AbstractAction = b.Builder.Build() + return b.setReward +} diff --git a/action/protocol/vote/protocol.go b/action/protocol/vote/protocol.go index b3b1c92a99..1312da9e0c 100644 --- a/action/protocol/vote/protocol.go +++ b/action/protocol/vote/protocol.go @@ -52,9 +52,13 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St } if raCtx.EnableGasCharge { // Load or create account for producer - producer, err := account.LoadOrCreateAccount(sm, raCtx.ProducerAddr, big.NewInt(0)) + producer, err := account.LoadOrCreateAccount(sm, raCtx.Producer.Bech32(), big.NewInt(0)) if err != nil { - return nil, errors.Wrapf(err, "failed to load or create the account of block producer %s", raCtx.ProducerAddr) + return nil, errors.Wrapf( + err, + "failed to load or create the account of block producer %s", + raCtx.Producer.Bech32(), + ) } gas, err := vote.IntrinsicGas() if err != nil { @@ -78,7 +82,7 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St return nil, errors.Wrapf(err, "failed to compensate gas to producer") } // Put updated producer's state to trie - if err := account.StoreAccount(sm, raCtx.ProducerAddr, producer); err != nil { + if err := account.StoreAccount(sm, raCtx.Producer.Bech32(), producer); err != nil { return nil, errors.Wrap(err, "failed to update pending account changes to trie") } *raCtx.GasLimit -= gas diff --git a/actpool/actpool_test.go b/actpool/actpool_test.go index 4a9736a6c7..0419afb775 100644 --- a/actpool/actpool_test.go +++ b/actpool/actpool_test.go @@ -100,7 +100,7 @@ func TestActPool_validateGenericAction(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -435,7 +435,7 @@ func TestActPool_removeConfirmedActs(t *testing.T) { gasLimit := uint64(1000000) ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -601,7 +601,7 @@ func TestActPool_Reset(t *testing.T) { gasLimit := uint64(1000000) ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -718,7 +718,7 @@ func TestActPool_Reset(t *testing.T) { require.NoError(err) ctx = protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -832,7 +832,7 @@ func TestActPool_Reset(t *testing.T) { ctx = protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -1073,7 +1073,7 @@ func TestActPool_GetSize(t *testing.T) { ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index f064e6323d..874b8c17cb 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -805,11 +805,15 @@ func (bc *blockchain) ExecuteContractRead(ex *action.Execution) (*action.Receipt if err != nil { return nil, errors.Wrap(err, "failed to obtain working set from state factory") } + producer, err := address.Bech32ToAddress(blk.ProducerAddress()) + if err != nil { + return nil, err + } gasLimit := genesis.BlockGasLimit return evm.ExecuteContract( blk.Height(), blk.HashBlock(), - blk.PublicKey(), + producer, blk.Timestamp(), ws, ex, @@ -837,11 +841,23 @@ func (bc *blockchain) CreateState(addr string, init *big.Int) (*state.Account, e return nil, errors.Wrap(err, "failed to get genesis block") } gasLimit := genesis.BlockGasLimit + callerAddr, err := address.Bech32ToAddress(addr) + if err != nil { + return nil, err + } + producer, err := address.Bech32ToAddress(genesisBlk.ProducerAddress()) + if err != nil { + return nil, err + } ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: genesisBlk.ProducerAddress(), + EpochNumber: 0, + Producer: producer, GasLimit: &gasLimit, EnableGasCharge: bc.config.Chain.EnableGasCharge, + Caller: callerAddr, + ActionHash: hash.ZeroHash32B, + Nonce: 0, }) if _, _, err = ws.RunActions(ctx, 0, nil); err != nil { return nil, errors.Wrap(err, "failed to run the account creation") @@ -1103,13 +1119,17 @@ func (bc *blockchain) runActions( } gasLimit := genesis.BlockGasLimit // update state factory + producer, err := address.Bech32ToAddress(acts.BlockProducerAddr()) + if err != nil { + return hash.ZeroHash32B, nil, err + } ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ + EpochNumber: 0, // TODO: need to get the actual epoch number from RollDPoS BlockHeight: acts.BlockHeight(), BlockHash: acts.TxHash(), - ProducerPubKey: acts.BlockProducerPubKey(), BlockTimeStamp: int64(acts.BlockTimeStamp()), - ProducerAddr: acts.BlockProducerAddr(), + Producer: producer, GasLimit: &gasLimit, EnableGasCharge: bc.config.Chain.EnableGasCharge, }) diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index fccb7d5f9e..bdf0e35b5d 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -965,7 +965,7 @@ func TestBlocks(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: ta.Addrinfo["producer"].Bech32(), + Producer: ta.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -1031,7 +1031,7 @@ func TestActions(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: ta.Addrinfo["producer"].Bech32(), + Producer: ta.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -1145,7 +1145,7 @@ func addCreatorToFactory(sf factory.Factory) error { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: ta.Addrinfo["producer"].Bech32(), + Producer: ta.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/blockchain/blockvalidator.go b/blockchain/blockvalidator.go index 429f7cd9c1..5142263b57 100644 --- a/blockchain/blockvalidator.go +++ b/blockchain/blockvalidator.go @@ -162,11 +162,15 @@ func (v *validator) validateActions( for _, selp := range actions { appendActionIndex(accountNonceMap, selp.SrcAddr(), selp.Nonce()) - ctx := protocol.WithValidateActionsCtx(context.Background(), - &protocol.ValidateActionsCtx{ + callerPKHash := keypair.HashPubKey(selp.SrcPubkey()) + ctx := protocol.WithValidateActionsCtx( + context.Background(), + protocol.ValidateActionsCtx{ BlockHeight: height, ProducerAddr: producerAddr.Bech32(), - }) + Caller: address.New(callerPKHash[:]), + }, + ) for _, validator := range v.actionEnvelopeValidators { wg.Add(1) diff --git a/blockchain/blockvalidator_test.go b/blockchain/blockvalidator_test.go index 689adf20ae..fe190bfe12 100644 --- a/blockchain/blockvalidator_test.go +++ b/blockchain/blockvalidator_test.go @@ -121,7 +121,7 @@ func TestWrongNonce(t *testing.T) { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: ta.Addrinfo["producer"].Bech32(), + Producer: ta.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/consensus/scheme/rolldpos/rolldpos_test.go b/consensus/scheme/rolldpos/rolldpos_test.go index ddd4ace5fc..d564bd95f7 100644 --- a/consensus/scheme/rolldpos/rolldpos_test.go +++ b/consensus/scheme/rolldpos/rolldpos_test.go @@ -351,7 +351,7 @@ func TestRollDPoSConsensus(t *testing.T) { gasLimit := testutil.TestGasLimit wsctx := protocol.WithRunActionsCtx(ctx, protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/explorer/explorer_test.go b/explorer/explorer_test.go index afb6be4f53..49cf7a07f8 100644 --- a/explorer/explorer_test.go +++ b/explorer/explorer_test.go @@ -1212,7 +1212,7 @@ func addCreatorToFactory(sf factory.Factory) error { gasLimit := testutil.TestGasLimit ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: ta.Addrinfo["producer"].Bech32(), + Producer: ta.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) diff --git a/proto/action.pb.go b/proto/action.pb.go index 2372381cb6..d7744f5389 100644 --- a/proto/action.pb.go +++ b/proto/action.pb.go @@ -19,10 +19,33 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +type RewardType int32 + +const ( + RewardType_Block RewardType = 0 + RewardType_Epoch RewardType = 1 +) + +var RewardType_name = map[int32]string{ + 0: "Block", + 1: "Epoch", +} +var RewardType_value = map[string]int32{ + "Block": 0, + "Epoch": 1, +} + +func (x RewardType) String() string { + return proto.EnumName(RewardType_name, int32(x)) +} +func (RewardType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_action_7c3e570acfb303ca, []int{0} +} + type TransferPb struct { // used by state-based model Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` - Recipient string `protobuf:"bytes,2,opt,name=recipient" json:"recipient,omitempty"` + Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -33,7 +56,7 @@ func (m *TransferPb) Reset() { *m = TransferPb{} } func (m *TransferPb) String() string { return proto.CompactTextString(m) } func (*TransferPb) ProtoMessage() {} func (*TransferPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{0} + return fileDescriptor_action_7c3e570acfb303ca, []int{0} } func (m *TransferPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TransferPb.Unmarshal(m, b) @@ -75,8 +98,8 @@ func (m *TransferPb) GetPayload() []byte { } type VotePb struct { - Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp" json:"timestamp,omitempty"` - VoteeAddress string `protobuf:"bytes,2,opt,name=voteeAddress" json:"voteeAddress,omitempty"` + Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + VoteeAddress string `protobuf:"bytes,2,opt,name=voteeAddress,proto3" json:"voteeAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -86,7 +109,7 @@ func (m *VotePb) Reset() { *m = VotePb{} } func (m *VotePb) String() string { return proto.CompactTextString(m) } func (*VotePb) ProtoMessage() {} func (*VotePb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{1} + return fileDescriptor_action_7c3e570acfb303ca, []int{1} } func (m *VotePb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_VotePb.Unmarshal(m, b) @@ -122,7 +145,7 @@ func (m *VotePb) GetVoteeAddress() string { type ExecutionPb struct { Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` - Contract string `protobuf:"bytes,2,opt,name=contract" json:"contract,omitempty"` + Contract string `protobuf:"bytes,2,opt,name=contract,proto3" json:"contract,omitempty"` Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -133,7 +156,7 @@ func (m *ExecutionPb) Reset() { *m = ExecutionPb{} } func (m *ExecutionPb) String() string { return proto.CompactTextString(m) } func (*ExecutionPb) ProtoMessage() {} func (*ExecutionPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{2} + return fileDescriptor_action_7c3e570acfb303ca, []int{2} } func (m *ExecutionPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ExecutionPb.Unmarshal(m, b) @@ -176,11 +199,11 @@ func (m *ExecutionPb) GetData() []byte { type StartSubChainPb struct { // TODO: chainID chould be assigned by system and returned via a receipt - ChainID uint32 `protobuf:"varint,1,opt,name=chainID" json:"chainID,omitempty"` + ChainID uint32 `protobuf:"varint,1,opt,name=chainID,proto3" json:"chainID,omitempty"` SecurityDeposit []byte `protobuf:"bytes,2,opt,name=securityDeposit,proto3" json:"securityDeposit,omitempty"` OperationDeposit []byte `protobuf:"bytes,3,opt,name=operationDeposit,proto3" json:"operationDeposit,omitempty"` - StartHeight uint64 `protobuf:"varint,4,opt,name=startHeight" json:"startHeight,omitempty"` - ParentHeightOffset uint64 `protobuf:"varint,5,opt,name=parentHeightOffset" json:"parentHeightOffset,omitempty"` + StartHeight uint64 `protobuf:"varint,4,opt,name=startHeight,proto3" json:"startHeight,omitempty"` + ParentHeightOffset uint64 `protobuf:"varint,5,opt,name=parentHeightOffset,proto3" json:"parentHeightOffset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -190,7 +213,7 @@ func (m *StartSubChainPb) Reset() { *m = StartSubChainPb{} } func (m *StartSubChainPb) String() string { return proto.CompactTextString(m) } func (*StartSubChainPb) ProtoMessage() {} func (*StartSubChainPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{3} + return fileDescriptor_action_7c3e570acfb303ca, []int{3} } func (m *StartSubChainPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_StartSubChainPb.Unmarshal(m, b) @@ -246,9 +269,9 @@ func (m *StartSubChainPb) GetParentHeightOffset() uint64 { } type StopSubChainPb struct { - ChainID uint32 `protobuf:"varint,1,opt,name=chainID" json:"chainID,omitempty"` - StopHeight uint64 `protobuf:"varint,2,opt,name=stopHeight" json:"stopHeight,omitempty"` - SubChainAddress string `protobuf:"bytes,3,opt,name=subChainAddress" json:"subChainAddress,omitempty"` + ChainID uint32 `protobuf:"varint,1,opt,name=chainID,proto3" json:"chainID,omitempty"` + StopHeight uint64 `protobuf:"varint,2,opt,name=stopHeight,proto3" json:"stopHeight,omitempty"` + SubChainAddress string `protobuf:"bytes,3,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -258,7 +281,7 @@ func (m *StopSubChainPb) Reset() { *m = StopSubChainPb{} } func (m *StopSubChainPb) String() string { return proto.CompactTextString(m) } func (*StopSubChainPb) ProtoMessage() {} func (*StopSubChainPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{4} + return fileDescriptor_action_7c3e570acfb303ca, []int{4} } func (m *StopSubChainPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_StopSubChainPb.Unmarshal(m, b) @@ -300,7 +323,7 @@ func (m *StopSubChainPb) GetSubChainAddress() string { } type MerkleRoot struct { - Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -311,7 +334,7 @@ func (m *MerkleRoot) Reset() { *m = MerkleRoot{} } func (m *MerkleRoot) String() string { return proto.CompactTextString(m) } func (*MerkleRoot) ProtoMessage() {} func (*MerkleRoot) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{5} + return fileDescriptor_action_7c3e570acfb303ca, []int{5} } func (m *MerkleRoot) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_MerkleRoot.Unmarshal(m, b) @@ -346,9 +369,9 @@ func (m *MerkleRoot) GetValue() []byte { } type PutBlockPb struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` - Height uint64 `protobuf:"varint,2,opt,name=height" json:"height,omitempty"` - Roots []*MerkleRoot `protobuf:"bytes,3,rep,name=roots" json:"roots,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` + Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + Roots []*MerkleRoot `protobuf:"bytes,3,rep,name=roots,proto3" json:"roots,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -358,7 +381,7 @@ func (m *PutBlockPb) Reset() { *m = PutBlockPb{} } func (m *PutBlockPb) String() string { return proto.CompactTextString(m) } func (*PutBlockPb) ProtoMessage() {} func (*PutBlockPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{6} + return fileDescriptor_action_7c3e570acfb303ca, []int{6} } func (m *PutBlockPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PutBlockPb.Unmarshal(m, b) @@ -400,9 +423,9 @@ func (m *PutBlockPb) GetRoots() []*MerkleRoot { } type CreateDepositPb struct { - ChainID uint32 `protobuf:"varint,1,opt,name=chainID" json:"chainID,omitempty"` + ChainID uint32 `protobuf:"varint,1,opt,name=chainID,proto3" json:"chainID,omitempty"` Amount []byte `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` - Recipient string `protobuf:"bytes,3,opt,name=recipient" json:"recipient,omitempty"` + Recipient string `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -412,7 +435,7 @@ func (m *CreateDepositPb) Reset() { *m = CreateDepositPb{} } func (m *CreateDepositPb) String() string { return proto.CompactTextString(m) } func (*CreateDepositPb) ProtoMessage() {} func (*CreateDepositPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{7} + return fileDescriptor_action_7c3e570acfb303ca, []int{7} } func (m *CreateDepositPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CreateDepositPb.Unmarshal(m, b) @@ -455,8 +478,8 @@ func (m *CreateDepositPb) GetRecipient() string { type SettleDepositPb struct { Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` - Recipient string `protobuf:"bytes,2,opt,name=recipient" json:"recipient,omitempty"` - Index uint64 `protobuf:"varint,3,opt,name=index" json:"index,omitempty"` + Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` + Index uint64 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -466,7 +489,7 @@ func (m *SettleDepositPb) Reset() { *m = SettleDepositPb{} } func (m *SettleDepositPb) String() string { return proto.CompactTextString(m) } func (*SettleDepositPb) ProtoMessage() {} func (*SettleDepositPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{8} + return fileDescriptor_action_7c3e570acfb303ca, []int{8} } func (m *SettleDepositPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_SettleDepositPb.Unmarshal(m, b) @@ -518,7 +541,7 @@ func (m *CreatePlumChainPb) Reset() { *m = CreatePlumChainPb{} } func (m *CreatePlumChainPb) String() string { return proto.CompactTextString(m) } func (*CreatePlumChainPb) ProtoMessage() {} func (*CreatePlumChainPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{9} + return fileDescriptor_action_7c3e570acfb303ca, []int{9} } func (m *CreatePlumChainPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CreatePlumChainPb.Unmarshal(m, b) @@ -539,7 +562,7 @@ func (m *CreatePlumChainPb) XXX_DiscardUnknown() { var xxx_messageInfo_CreatePlumChainPb proto.InternalMessageInfo type TerminatePlumChainPb struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -549,7 +572,7 @@ func (m *TerminatePlumChainPb) Reset() { *m = TerminatePlumChainPb{} } func (m *TerminatePlumChainPb) String() string { return proto.CompactTextString(m) } func (*TerminatePlumChainPb) ProtoMessage() {} func (*TerminatePlumChainPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{10} + return fileDescriptor_action_7c3e570acfb303ca, []int{10} } func (m *TerminatePlumChainPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TerminatePlumChainPb.Unmarshal(m, b) @@ -577,9 +600,9 @@ func (m *TerminatePlumChainPb) GetSubChainAddress() string { } type PlumPutBlockPb struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` - Height uint64 `protobuf:"varint,2,opt,name=height" json:"height,omitempty"` - Roots map[string][]byte `protobuf:"bytes,3,rep,name=roots" json:"roots,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value,proto3"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` + Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + Roots map[string][]byte `protobuf:"bytes,3,rep,name=roots,proto3" json:"roots,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -589,7 +612,7 @@ func (m *PlumPutBlockPb) Reset() { *m = PlumPutBlockPb{} } func (m *PlumPutBlockPb) String() string { return proto.CompactTextString(m) } func (*PlumPutBlockPb) ProtoMessage() {} func (*PlumPutBlockPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{11} + return fileDescriptor_action_7c3e570acfb303ca, []int{11} } func (m *PlumPutBlockPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumPutBlockPb.Unmarshal(m, b) @@ -631,9 +654,9 @@ func (m *PlumPutBlockPb) GetRoots() map[string][]byte { } type PlumCreateDepositPb struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` Amount []byte `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` - Recipient string `protobuf:"bytes,3,opt,name=recipient" json:"recipient,omitempty"` + Recipient string `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -643,7 +666,7 @@ func (m *PlumCreateDepositPb) Reset() { *m = PlumCreateDepositPb{} } func (m *PlumCreateDepositPb) String() string { return proto.CompactTextString(m) } func (*PlumCreateDepositPb) ProtoMessage() {} func (*PlumCreateDepositPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{12} + return fileDescriptor_action_7c3e570acfb303ca, []int{12} } func (m *PlumCreateDepositPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumCreateDepositPb.Unmarshal(m, b) @@ -685,13 +708,13 @@ func (m *PlumCreateDepositPb) GetRecipient() string { } type PlumStartExitPb struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` PreviousTransfer []byte `protobuf:"bytes,2,opt,name=previousTransfer,proto3" json:"previousTransfer,omitempty"` PreviousTransferBlockProof []byte `protobuf:"bytes,3,opt,name=previousTransferBlockProof,proto3" json:"previousTransferBlockProof,omitempty"` - PreviousTransferBlockHeight uint64 `protobuf:"varint,4,opt,name=previousTransferBlockHeight" json:"previousTransferBlockHeight,omitempty"` + PreviousTransferBlockHeight uint64 `protobuf:"varint,4,opt,name=previousTransferBlockHeight,proto3" json:"previousTransferBlockHeight,omitempty"` ExitTransfer []byte `protobuf:"bytes,5,opt,name=exitTransfer,proto3" json:"exitTransfer,omitempty"` ExitTransferBlockProof []byte `protobuf:"bytes,6,opt,name=exitTransferBlockProof,proto3" json:"exitTransferBlockProof,omitempty"` - ExitTransferBlockHeight uint64 `protobuf:"varint,7,opt,name=exitTransferBlockHeight" json:"exitTransferBlockHeight,omitempty"` + ExitTransferBlockHeight uint64 `protobuf:"varint,7,opt,name=exitTransferBlockHeight,proto3" json:"exitTransferBlockHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -701,7 +724,7 @@ func (m *PlumStartExitPb) Reset() { *m = PlumStartExitPb{} } func (m *PlumStartExitPb) String() string { return proto.CompactTextString(m) } func (*PlumStartExitPb) ProtoMessage() {} func (*PlumStartExitPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{13} + return fileDescriptor_action_7c3e570acfb303ca, []int{13} } func (m *PlumStartExitPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumStartExitPb.Unmarshal(m, b) @@ -771,11 +794,11 @@ func (m *PlumStartExitPb) GetExitTransferBlockHeight() uint64 { } type PlumChallengeExit struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` - CoinID uint64 `protobuf:"varint,2,opt,name=coinID" json:"coinID,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` + CoinID uint64 `protobuf:"varint,2,opt,name=coinID,proto3" json:"coinID,omitempty"` ChallengeTransfer []byte `protobuf:"bytes,3,opt,name=challengeTransfer,proto3" json:"challengeTransfer,omitempty"` ChallengeTransferBlockProof []byte `protobuf:"bytes,4,opt,name=challengeTransferBlockProof,proto3" json:"challengeTransferBlockProof,omitempty"` - ChallengeTransferBlockHeight uint64 `protobuf:"varint,5,opt,name=challengeTransferBlockHeight" json:"challengeTransferBlockHeight,omitempty"` + ChallengeTransferBlockHeight uint64 `protobuf:"varint,5,opt,name=challengeTransferBlockHeight,proto3" json:"challengeTransferBlockHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -785,7 +808,7 @@ func (m *PlumChallengeExit) Reset() { *m = PlumChallengeExit{} } func (m *PlumChallengeExit) String() string { return proto.CompactTextString(m) } func (*PlumChallengeExit) ProtoMessage() {} func (*PlumChallengeExit) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{14} + return fileDescriptor_action_7c3e570acfb303ca, []int{14} } func (m *PlumChallengeExit) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumChallengeExit.Unmarshal(m, b) @@ -841,12 +864,12 @@ func (m *PlumChallengeExit) GetChallengeTransferBlockHeight() uint64 { } type PlumResponseChallengeExit struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` - CoinID uint64 `protobuf:"varint,2,opt,name=coinID" json:"coinID,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` + CoinID uint64 `protobuf:"varint,2,opt,name=coinID,proto3" json:"coinID,omitempty"` ChallengeTransfer []byte `protobuf:"bytes,3,opt,name=challengeTransfer,proto3" json:"challengeTransfer,omitempty"` ResponseTransfer []byte `protobuf:"bytes,4,opt,name=responseTransfer,proto3" json:"responseTransfer,omitempty"` ResponseTransferBlockProof []byte `protobuf:"bytes,5,opt,name=responseTransferBlockProof,proto3" json:"responseTransferBlockProof,omitempty"` - PreviousTransferBlockHeight uint64 `protobuf:"varint,6,opt,name=previousTransferBlockHeight" json:"previousTransferBlockHeight,omitempty"` + PreviousTransferBlockHeight uint64 `protobuf:"varint,6,opt,name=previousTransferBlockHeight,proto3" json:"previousTransferBlockHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -856,7 +879,7 @@ func (m *PlumResponseChallengeExit) Reset() { *m = PlumResponseChallenge func (m *PlumResponseChallengeExit) String() string { return proto.CompactTextString(m) } func (*PlumResponseChallengeExit) ProtoMessage() {} func (*PlumResponseChallengeExit) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{15} + return fileDescriptor_action_7c3e570acfb303ca, []int{15} } func (m *PlumResponseChallengeExit) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumResponseChallengeExit.Unmarshal(m, b) @@ -919,8 +942,8 @@ func (m *PlumResponseChallengeExit) GetPreviousTransferBlockHeight() uint64 { } type PlumFinalizeExit struct { - SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress" json:"subChainAddress,omitempty"` - CoinID uint64 `protobuf:"varint,2,opt,name=coinID" json:"coinID,omitempty"` + SubChainAddress string `protobuf:"bytes,1,opt,name=subChainAddress,proto3" json:"subChainAddress,omitempty"` + CoinID uint64 `protobuf:"varint,2,opt,name=coinID,proto3" json:"coinID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -930,7 +953,7 @@ func (m *PlumFinalizeExit) Reset() { *m = PlumFinalizeExit{} } func (m *PlumFinalizeExit) String() string { return proto.CompactTextString(m) } func (*PlumFinalizeExit) ProtoMessage() {} func (*PlumFinalizeExit) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{16} + return fileDescriptor_action_7c3e570acfb303ca, []int{16} } func (m *PlumFinalizeExit) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumFinalizeExit.Unmarshal(m, b) @@ -966,7 +989,7 @@ func (m *PlumFinalizeExit) GetCoinID() uint64 { // plum sub chain APIs type PlumSettleDepositPb struct { - CoinID uint64 `protobuf:"varint,1,opt,name=coinID" json:"coinID,omitempty"` + CoinID uint64 `protobuf:"varint,1,opt,name=coinID,proto3" json:"coinID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -976,7 +999,7 @@ func (m *PlumSettleDepositPb) Reset() { *m = PlumSettleDepositPb{} } func (m *PlumSettleDepositPb) String() string { return proto.CompactTextString(m) } func (*PlumSettleDepositPb) ProtoMessage() {} func (*PlumSettleDepositPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{17} + return fileDescriptor_action_7c3e570acfb303ca, []int{17} } func (m *PlumSettleDepositPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumSettleDepositPb.Unmarshal(m, b) @@ -1004,10 +1027,10 @@ func (m *PlumSettleDepositPb) GetCoinID() uint64 { } type PlumTransferPb struct { - CoinID uint64 `protobuf:"varint,1,opt,name=coinID" json:"coinID,omitempty"` + CoinID uint64 `protobuf:"varint,1,opt,name=coinID,proto3" json:"coinID,omitempty"` Denomination []byte `protobuf:"bytes,2,opt,name=denomination,proto3" json:"denomination,omitempty"` - Owner string `protobuf:"bytes,3,opt,name=owner" json:"owner,omitempty"` - Recipient string `protobuf:"bytes,4,opt,name=recipient" json:"recipient,omitempty"` + Owner string `protobuf:"bytes,3,opt,name=owner,proto3" json:"owner,omitempty"` + Recipient string `protobuf:"bytes,4,opt,name=recipient,proto3" json:"recipient,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1017,7 +1040,7 @@ func (m *PlumTransferPb) Reset() { *m = PlumTransferPb{} } func (m *PlumTransferPb) String() string { return proto.CompactTextString(m) } func (*PlumTransferPb) ProtoMessage() {} func (*PlumTransferPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{18} + return fileDescriptor_action_7c3e570acfb303ca, []int{18} } func (m *PlumTransferPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_PlumTransferPb.Unmarshal(m, b) @@ -1066,12 +1089,12 @@ func (m *PlumTransferPb) GetRecipient() string { } type ActionPb struct { - Version uint32 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"` + Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` // TODO: we should remove sender address later - Sender string `protobuf:"bytes,2,opt,name=sender" json:"sender,omitempty"` + Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` SenderPubKey []byte `protobuf:"bytes,3,opt,name=senderPubKey,proto3" json:"senderPubKey,omitempty"` - Nonce uint64 `protobuf:"varint,4,opt,name=nonce" json:"nonce,omitempty"` - GasLimit uint64 `protobuf:"varint,5,opt,name=gasLimit" json:"gasLimit,omitempty"` + Nonce uint64 `protobuf:"varint,4,opt,name=nonce,proto3" json:"nonce,omitempty"` + GasLimit uint64 `protobuf:"varint,5,opt,name=gasLimit,proto3" json:"gasLimit,omitempty"` GasPrice []byte `protobuf:"bytes,6,opt,name=gasPrice,proto3" json:"gasPrice,omitempty"` Signature []byte `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"` // Types that are valid to be assigned to Action: @@ -1093,6 +1116,10 @@ type ActionPb struct { // *ActionPb_PlumFinalizeExit // *ActionPb_PlumSettleDeposit // *ActionPb_PlumTransfer + // *ActionPb_DepositToRewardingFund + // *ActionPb_ClaimFromRewardingFund + // *ActionPb_SetReward + // *ActionPb_GrantReward Action isActionPb_Action `protobuf_oneof:"action"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -1103,7 +1130,7 @@ func (m *ActionPb) Reset() { *m = ActionPb{} } func (m *ActionPb) String() string { return proto.CompactTextString(m) } func (*ActionPb) ProtoMessage() {} func (*ActionPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{19} + return fileDescriptor_action_7c3e570acfb303ca, []int{19} } func (m *ActionPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ActionPb.Unmarshal(m, b) @@ -1123,136 +1150,194 @@ func (m *ActionPb) XXX_DiscardUnknown() { var xxx_messageInfo_ActionPb proto.InternalMessageInfo +func (m *ActionPb) GetVersion() uint32 { + if m != nil { + return m.Version + } + return 0 +} + +func (m *ActionPb) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *ActionPb) GetSenderPubKey() []byte { + if m != nil { + return m.SenderPubKey + } + return nil +} + +func (m *ActionPb) GetNonce() uint64 { + if m != nil { + return m.Nonce + } + return 0 +} + +func (m *ActionPb) GetGasLimit() uint64 { + if m != nil { + return m.GasLimit + } + return 0 +} + +func (m *ActionPb) GetGasPrice() []byte { + if m != nil { + return m.GasPrice + } + return nil +} + +func (m *ActionPb) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + type isActionPb_Action interface { isActionPb_Action() } type ActionPb_Transfer struct { - Transfer *TransferPb `protobuf:"bytes,10,opt,name=transfer,oneof"` + Transfer *TransferPb `protobuf:"bytes,10,opt,name=transfer,proto3,oneof"` } + type ActionPb_Vote struct { - Vote *VotePb `protobuf:"bytes,11,opt,name=vote,oneof"` + Vote *VotePb `protobuf:"bytes,11,opt,name=vote,proto3,oneof"` } + type ActionPb_Execution struct { - Execution *ExecutionPb `protobuf:"bytes,12,opt,name=execution,oneof"` + Execution *ExecutionPb `protobuf:"bytes,12,opt,name=execution,proto3,oneof"` } + type ActionPb_StartSubChain struct { - StartSubChain *StartSubChainPb `protobuf:"bytes,13,opt,name=startSubChain,oneof"` + StartSubChain *StartSubChainPb `protobuf:"bytes,13,opt,name=startSubChain,proto3,oneof"` } + type ActionPb_StopSubChain struct { - StopSubChain *StopSubChainPb `protobuf:"bytes,14,opt,name=stopSubChain,oneof"` + StopSubChain *StopSubChainPb `protobuf:"bytes,14,opt,name=stopSubChain,proto3,oneof"` } + type ActionPb_PutBlock struct { - PutBlock *PutBlockPb `protobuf:"bytes,15,opt,name=putBlock,oneof"` + PutBlock *PutBlockPb `protobuf:"bytes,15,opt,name=putBlock,proto3,oneof"` } + type ActionPb_CreateDeposit struct { - CreateDeposit *CreateDepositPb `protobuf:"bytes,16,opt,name=createDeposit,oneof"` + CreateDeposit *CreateDepositPb `protobuf:"bytes,16,opt,name=createDeposit,proto3,oneof"` } + type ActionPb_SettleDeposit struct { - SettleDeposit *SettleDepositPb `protobuf:"bytes,17,opt,name=settleDeposit,oneof"` + SettleDeposit *SettleDepositPb `protobuf:"bytes,17,opt,name=settleDeposit,proto3,oneof"` } + type ActionPb_CreatePlumChain struct { - CreatePlumChain *CreatePlumChainPb `protobuf:"bytes,18,opt,name=createPlumChain,oneof"` + CreatePlumChain *CreatePlumChainPb `protobuf:"bytes,18,opt,name=createPlumChain,proto3,oneof"` } + type ActionPb_TerminatePlumChain struct { - TerminatePlumChain *TerminatePlumChainPb `protobuf:"bytes,19,opt,name=terminatePlumChain,oneof"` + TerminatePlumChain *TerminatePlumChainPb `protobuf:"bytes,19,opt,name=terminatePlumChain,proto3,oneof"` } + type ActionPb_PlumPutBlock struct { - PlumPutBlock *PlumPutBlockPb `protobuf:"bytes,20,opt,name=plumPutBlock,oneof"` + PlumPutBlock *PlumPutBlockPb `protobuf:"bytes,20,opt,name=plumPutBlock,proto3,oneof"` } + type ActionPb_PlumCreateDeposit struct { - PlumCreateDeposit *PlumCreateDepositPb `protobuf:"bytes,21,opt,name=plumCreateDeposit,oneof"` + PlumCreateDeposit *PlumCreateDepositPb `protobuf:"bytes,21,opt,name=plumCreateDeposit,proto3,oneof"` } + type ActionPb_PlumStartExit struct { - PlumStartExit *PlumStartExitPb `protobuf:"bytes,22,opt,name=plumStartExit,oneof"` + PlumStartExit *PlumStartExitPb `protobuf:"bytes,22,opt,name=plumStartExit,proto3,oneof"` } + type ActionPb_PlumChallengeExit struct { - PlumChallengeExit *PlumChallengeExit `protobuf:"bytes,23,opt,name=plumChallengeExit,oneof"` + PlumChallengeExit *PlumChallengeExit `protobuf:"bytes,23,opt,name=plumChallengeExit,proto3,oneof"` } + type ActionPb_PlumResponseChallengeExit struct { - PlumResponseChallengeExit *PlumResponseChallengeExit `protobuf:"bytes,24,opt,name=plumResponseChallengeExit,oneof"` + PlumResponseChallengeExit *PlumResponseChallengeExit `protobuf:"bytes,24,opt,name=plumResponseChallengeExit,proto3,oneof"` } + type ActionPb_PlumFinalizeExit struct { - PlumFinalizeExit *PlumFinalizeExit `protobuf:"bytes,25,opt,name=plumFinalizeExit,oneof"` + PlumFinalizeExit *PlumFinalizeExit `protobuf:"bytes,25,opt,name=plumFinalizeExit,proto3,oneof"` } + type ActionPb_PlumSettleDeposit struct { - PlumSettleDeposit *PlumSettleDepositPb `protobuf:"bytes,26,opt,name=plumSettleDeposit,oneof"` + PlumSettleDeposit *PlumSettleDepositPb `protobuf:"bytes,26,opt,name=plumSettleDeposit,proto3,oneof"` } -type ActionPb_PlumTransfer struct { - PlumTransfer *PlumTransferPb `protobuf:"bytes,27,opt,name=plumTransfer,oneof"` -} - -func (*ActionPb_Transfer) isActionPb_Action() {} -func (*ActionPb_Vote) isActionPb_Action() {} -func (*ActionPb_Execution) isActionPb_Action() {} -func (*ActionPb_StartSubChain) isActionPb_Action() {} -func (*ActionPb_StopSubChain) isActionPb_Action() {} -func (*ActionPb_PutBlock) isActionPb_Action() {} -func (*ActionPb_CreateDeposit) isActionPb_Action() {} -func (*ActionPb_SettleDeposit) isActionPb_Action() {} -func (*ActionPb_CreatePlumChain) isActionPb_Action() {} -func (*ActionPb_TerminatePlumChain) isActionPb_Action() {} -func (*ActionPb_PlumPutBlock) isActionPb_Action() {} -func (*ActionPb_PlumCreateDeposit) isActionPb_Action() {} -func (*ActionPb_PlumStartExit) isActionPb_Action() {} -func (*ActionPb_PlumChallengeExit) isActionPb_Action() {} -func (*ActionPb_PlumResponseChallengeExit) isActionPb_Action() {} -func (*ActionPb_PlumFinalizeExit) isActionPb_Action() {} -func (*ActionPb_PlumSettleDeposit) isActionPb_Action() {} -func (*ActionPb_PlumTransfer) isActionPb_Action() {} -func (m *ActionPb) GetAction() isActionPb_Action { - if m != nil { - return m.Action - } - return nil +type ActionPb_PlumTransfer struct { + PlumTransfer *PlumTransferPb `protobuf:"bytes,27,opt,name=plumTransfer,proto3,oneof"` } -func (m *ActionPb) GetVersion() uint32 { - if m != nil { - return m.Version - } - return 0 +type ActionPb_DepositToRewardingFund struct { + DepositToRewardingFund *DepositToRewardingFund `protobuf:"bytes,30,opt,name=depositToRewardingFund,proto3,oneof"` } -func (m *ActionPb) GetSender() string { - if m != nil { - return m.Sender - } - return "" +type ActionPb_ClaimFromRewardingFund struct { + ClaimFromRewardingFund *ClaimFromRewardingFund `protobuf:"bytes,31,opt,name=claimFromRewardingFund,proto3,oneof"` } -func (m *ActionPb) GetSenderPubKey() []byte { - if m != nil { - return m.SenderPubKey - } - return nil +type ActionPb_SetReward struct { + SetReward *SetReward `protobuf:"bytes,32,opt,name=setReward,proto3,oneof"` } -func (m *ActionPb) GetNonce() uint64 { - if m != nil { - return m.Nonce - } - return 0 +type ActionPb_GrantReward struct { + GrantReward *GrantReward `protobuf:"bytes,33,opt,name=grantReward,proto3,oneof"` } -func (m *ActionPb) GetGasLimit() uint64 { - if m != nil { - return m.GasLimit - } - return 0 -} +func (*ActionPb_Transfer) isActionPb_Action() {} -func (m *ActionPb) GetGasPrice() []byte { - if m != nil { - return m.GasPrice - } - return nil -} +func (*ActionPb_Vote) isActionPb_Action() {} -func (m *ActionPb) GetSignature() []byte { +func (*ActionPb_Execution) isActionPb_Action() {} + +func (*ActionPb_StartSubChain) isActionPb_Action() {} + +func (*ActionPb_StopSubChain) isActionPb_Action() {} + +func (*ActionPb_PutBlock) isActionPb_Action() {} + +func (*ActionPb_CreateDeposit) isActionPb_Action() {} + +func (*ActionPb_SettleDeposit) isActionPb_Action() {} + +func (*ActionPb_CreatePlumChain) isActionPb_Action() {} + +func (*ActionPb_TerminatePlumChain) isActionPb_Action() {} + +func (*ActionPb_PlumPutBlock) isActionPb_Action() {} + +func (*ActionPb_PlumCreateDeposit) isActionPb_Action() {} + +func (*ActionPb_PlumStartExit) isActionPb_Action() {} + +func (*ActionPb_PlumChallengeExit) isActionPb_Action() {} + +func (*ActionPb_PlumResponseChallengeExit) isActionPb_Action() {} + +func (*ActionPb_PlumFinalizeExit) isActionPb_Action() {} + +func (*ActionPb_PlumSettleDeposit) isActionPb_Action() {} + +func (*ActionPb_PlumTransfer) isActionPb_Action() {} + +func (*ActionPb_DepositToRewardingFund) isActionPb_Action() {} + +func (*ActionPb_ClaimFromRewardingFund) isActionPb_Action() {} + +func (*ActionPb_SetReward) isActionPb_Action() {} + +func (*ActionPb_GrantReward) isActionPb_Action() {} + +func (m *ActionPb) GetAction() isActionPb_Action { if m != nil { - return m.Signature + return m.Action } return nil } @@ -1383,6 +1468,34 @@ func (m *ActionPb) GetPlumTransfer() *PlumTransferPb { return nil } +func (m *ActionPb) GetDepositToRewardingFund() *DepositToRewardingFund { + if x, ok := m.GetAction().(*ActionPb_DepositToRewardingFund); ok { + return x.DepositToRewardingFund + } + return nil +} + +func (m *ActionPb) GetClaimFromRewardingFund() *ClaimFromRewardingFund { + if x, ok := m.GetAction().(*ActionPb_ClaimFromRewardingFund); ok { + return x.ClaimFromRewardingFund + } + return nil +} + +func (m *ActionPb) GetSetReward() *SetReward { + if x, ok := m.GetAction().(*ActionPb_SetReward); ok { + return x.SetReward + } + return nil +} + +func (m *ActionPb) GetGrantReward() *GrantReward { + if x, ok := m.GetAction().(*ActionPb_GrantReward); ok { + return x.GrantReward + } + return nil +} + // XXX_OneofFuncs is for the internal use of the proto package. func (*ActionPb) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _ActionPb_OneofMarshaler, _ActionPb_OneofUnmarshaler, _ActionPb_OneofSizer, []interface{}{ @@ -1404,6 +1517,10 @@ func (*ActionPb) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) erro (*ActionPb_PlumFinalizeExit)(nil), (*ActionPb_PlumSettleDeposit)(nil), (*ActionPb_PlumTransfer)(nil), + (*ActionPb_DepositToRewardingFund)(nil), + (*ActionPb_ClaimFromRewardingFund)(nil), + (*ActionPb_SetReward)(nil), + (*ActionPb_GrantReward)(nil), } } @@ -1501,6 +1618,26 @@ func _ActionPb_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { if err := b.EncodeMessage(x.PlumTransfer); err != nil { return err } + case *ActionPb_DepositToRewardingFund: + b.EncodeVarint(30<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.DepositToRewardingFund); err != nil { + return err + } + case *ActionPb_ClaimFromRewardingFund: + b.EncodeVarint(31<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.ClaimFromRewardingFund); err != nil { + return err + } + case *ActionPb_SetReward: + b.EncodeVarint(32<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.SetReward); err != nil { + return err + } + case *ActionPb_GrantReward: + b.EncodeVarint(33<<3 | proto.WireBytes) + if err := b.EncodeMessage(x.GrantReward); err != nil { + return err + } case nil: default: return fmt.Errorf("ActionPb.Action has unexpected type %T", x) @@ -1655,6 +1792,38 @@ func _ActionPb_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffe err := b.DecodeMessage(msg) m.Action = &ActionPb_PlumTransfer{msg} return true, err + case 30: // action.depositToRewardingFund + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(DepositToRewardingFund) + err := b.DecodeMessage(msg) + m.Action = &ActionPb_DepositToRewardingFund{msg} + return true, err + case 31: // action.claimFromRewardingFund + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(ClaimFromRewardingFund) + err := b.DecodeMessage(msg) + m.Action = &ActionPb_ClaimFromRewardingFund{msg} + return true, err + case 32: // action.setReward + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(SetReward) + err := b.DecodeMessage(msg) + m.Action = &ActionPb_SetReward{msg} + return true, err + case 33: // action.grantReward + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + msg := new(GrantReward) + err := b.DecodeMessage(msg) + m.Action = &ActionPb_GrantReward{msg} + return true, err default: return false, nil } @@ -1754,6 +1923,26 @@ func _ActionPb_OneofSizer(msg proto.Message) (n int) { n += 2 // tag and wire n += proto.SizeVarint(uint64(s)) n += s + case *ActionPb_DepositToRewardingFund: + s := proto.Size(x.DepositToRewardingFund) + n += 2 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ActionPb_ClaimFromRewardingFund: + s := proto.Size(x.ClaimFromRewardingFund) + n += 2 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ActionPb_SetReward: + s := proto.Size(x.SetReward) + n += 2 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s + case *ActionPb_GrantReward: + s := proto.Size(x.GrantReward) + n += 2 // tag and wire + n += proto.SizeVarint(uint64(s)) + n += s case nil: default: panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) @@ -1763,11 +1952,11 @@ func _ActionPb_OneofSizer(msg proto.Message) (n int) { type ReceiptPb struct { ReturnValue []byte `protobuf:"bytes,1,opt,name=returnValue,proto3" json:"returnValue,omitempty"` - Status uint64 `protobuf:"varint,2,opt,name=status" json:"status,omitempty"` + Status uint64 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` ActHash []byte `protobuf:"bytes,3,opt,name=actHash,proto3" json:"actHash,omitempty"` - GasConsumed uint64 `protobuf:"varint,4,opt,name=gasConsumed" json:"gasConsumed,omitempty"` - ContractAddress string `protobuf:"bytes,5,opt,name=contractAddress" json:"contractAddress,omitempty"` - Logs []*LogPb `protobuf:"bytes,6,rep,name=logs" json:"logs,omitempty"` + GasConsumed uint64 `protobuf:"varint,4,opt,name=gasConsumed,proto3" json:"gasConsumed,omitempty"` + ContractAddress string `protobuf:"bytes,5,opt,name=contractAddress,proto3" json:"contractAddress,omitempty"` + Logs []*LogPb `protobuf:"bytes,6,rep,name=logs,proto3" json:"logs,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1777,7 +1966,7 @@ func (m *ReceiptPb) Reset() { *m = ReceiptPb{} } func (m *ReceiptPb) String() string { return proto.CompactTextString(m) } func (*ReceiptPb) ProtoMessage() {} func (*ReceiptPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{20} + return fileDescriptor_action_7c3e570acfb303ca, []int{20} } func (m *ReceiptPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReceiptPb.Unmarshal(m, b) @@ -1840,13 +2029,13 @@ func (m *ReceiptPb) GetLogs() []*LogPb { } type LogPb struct { - Address string `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Topics [][]byte `protobuf:"bytes,2,rep,name=topics,proto3" json:"topics,omitempty"` Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` - BlockNumber uint64 `protobuf:"varint,4,opt,name=blockNumber" json:"blockNumber,omitempty"` + BlockNumber uint64 `protobuf:"varint,4,opt,name=blockNumber,proto3" json:"blockNumber,omitempty"` TxnHash []byte `protobuf:"bytes,5,opt,name=txnHash,proto3" json:"txnHash,omitempty"` BlockHash []byte `protobuf:"bytes,6,opt,name=blockHash,proto3" json:"blockHash,omitempty"` - Index uint32 `protobuf:"varint,7,opt,name=index" json:"index,omitempty"` + Index uint32 `protobuf:"varint,7,opt,name=index,proto3" json:"index,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1856,7 +2045,7 @@ func (m *LogPb) Reset() { *m = LogPb{} } func (m *LogPb) String() string { return proto.CompactTextString(m) } func (*LogPb) ProtoMessage() {} func (*LogPb) Descriptor() ([]byte, []int) { - return fileDescriptor_action_3103ac96ff6de5a7, []int{21} + return fileDescriptor_action_7c3e570acfb303ca, []int{21} } func (m *LogPb) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_LogPb.Unmarshal(m, b) @@ -1925,6 +2114,190 @@ func (m *LogPb) GetIndex() uint32 { return 0 } +type DepositToRewardingFund struct { + Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DepositToRewardingFund) Reset() { *m = DepositToRewardingFund{} } +func (m *DepositToRewardingFund) String() string { return proto.CompactTextString(m) } +func (*DepositToRewardingFund) ProtoMessage() {} +func (*DepositToRewardingFund) Descriptor() ([]byte, []int) { + return fileDescriptor_action_7c3e570acfb303ca, []int{22} +} +func (m *DepositToRewardingFund) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DepositToRewardingFund.Unmarshal(m, b) +} +func (m *DepositToRewardingFund) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DepositToRewardingFund.Marshal(b, m, deterministic) +} +func (dst *DepositToRewardingFund) XXX_Merge(src proto.Message) { + xxx_messageInfo_DepositToRewardingFund.Merge(dst, src) +} +func (m *DepositToRewardingFund) XXX_Size() int { + return xxx_messageInfo_DepositToRewardingFund.Size(m) +} +func (m *DepositToRewardingFund) XXX_DiscardUnknown() { + xxx_messageInfo_DepositToRewardingFund.DiscardUnknown(m) +} + +var xxx_messageInfo_DepositToRewardingFund proto.InternalMessageInfo + +func (m *DepositToRewardingFund) GetAmount() []byte { + if m != nil { + return m.Amount + } + return nil +} + +func (m *DepositToRewardingFund) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type ClaimFromRewardingFund struct { + Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ClaimFromRewardingFund) Reset() { *m = ClaimFromRewardingFund{} } +func (m *ClaimFromRewardingFund) String() string { return proto.CompactTextString(m) } +func (*ClaimFromRewardingFund) ProtoMessage() {} +func (*ClaimFromRewardingFund) Descriptor() ([]byte, []int) { + return fileDescriptor_action_7c3e570acfb303ca, []int{23} +} +func (m *ClaimFromRewardingFund) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ClaimFromRewardingFund.Unmarshal(m, b) +} +func (m *ClaimFromRewardingFund) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ClaimFromRewardingFund.Marshal(b, m, deterministic) +} +func (dst *ClaimFromRewardingFund) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClaimFromRewardingFund.Merge(dst, src) +} +func (m *ClaimFromRewardingFund) XXX_Size() int { + return xxx_messageInfo_ClaimFromRewardingFund.Size(m) +} +func (m *ClaimFromRewardingFund) XXX_DiscardUnknown() { + xxx_messageInfo_ClaimFromRewardingFund.DiscardUnknown(m) +} + +var xxx_messageInfo_ClaimFromRewardingFund proto.InternalMessageInfo + +func (m *ClaimFromRewardingFund) GetAmount() []byte { + if m != nil { + return m.Amount + } + return nil +} + +func (m *ClaimFromRewardingFund) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type SetReward struct { + Amount []byte `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Type RewardType `protobuf:"varint,3,opt,name=type,proto3,enum=iproto.RewardType" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *SetReward) Reset() { *m = SetReward{} } +func (m *SetReward) String() string { return proto.CompactTextString(m) } +func (*SetReward) ProtoMessage() {} +func (*SetReward) Descriptor() ([]byte, []int) { + return fileDescriptor_action_7c3e570acfb303ca, []int{24} +} +func (m *SetReward) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_SetReward.Unmarshal(m, b) +} +func (m *SetReward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_SetReward.Marshal(b, m, deterministic) +} +func (dst *SetReward) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetReward.Merge(dst, src) +} +func (m *SetReward) XXX_Size() int { + return xxx_messageInfo_SetReward.Size(m) +} +func (m *SetReward) XXX_DiscardUnknown() { + xxx_messageInfo_SetReward.DiscardUnknown(m) +} + +var xxx_messageInfo_SetReward proto.InternalMessageInfo + +func (m *SetReward) GetAmount() []byte { + if m != nil { + return m.Amount + } + return nil +} + +func (m *SetReward) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func (m *SetReward) GetType() RewardType { + if m != nil { + return m.Type + } + return RewardType_Block +} + +type GrantReward struct { + Type RewardType `protobuf:"varint,1,opt,name=type,proto3,enum=iproto.RewardType" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GrantReward) Reset() { *m = GrantReward{} } +func (m *GrantReward) String() string { return proto.CompactTextString(m) } +func (*GrantReward) ProtoMessage() {} +func (*GrantReward) Descriptor() ([]byte, []int) { + return fileDescriptor_action_7c3e570acfb303ca, []int{25} +} +func (m *GrantReward) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GrantReward.Unmarshal(m, b) +} +func (m *GrantReward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GrantReward.Marshal(b, m, deterministic) +} +func (dst *GrantReward) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrantReward.Merge(dst, src) +} +func (m *GrantReward) XXX_Size() int { + return xxx_messageInfo_GrantReward.Size(m) +} +func (m *GrantReward) XXX_DiscardUnknown() { + xxx_messageInfo_GrantReward.DiscardUnknown(m) +} + +var xxx_messageInfo_GrantReward proto.InternalMessageInfo + +func (m *GrantReward) GetType() RewardType { + if m != nil { + return m.Type + } + return RewardType_Block +} + func init() { proto.RegisterType((*TransferPb)(nil), "iproto.TransferPb") proto.RegisterType((*VotePb)(nil), "iproto.VotePb") @@ -1949,98 +2322,114 @@ func init() { proto.RegisterType((*ActionPb)(nil), "iproto.ActionPb") proto.RegisterType((*ReceiptPb)(nil), "iproto.ReceiptPb") proto.RegisterType((*LogPb)(nil), "iproto.LogPb") -} - -func init() { proto.RegisterFile("action.proto", fileDescriptor_action_3103ac96ff6de5a7) } - -var fileDescriptor_action_3103ac96ff6de5a7 = []byte{ - // 1405 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x57, 0xcb, 0x6f, 0x1b, 0x37, - 0x13, 0x97, 0x64, 0x49, 0xb6, 0xc6, 0xb2, 0x25, 0xd3, 0xfe, 0x1c, 0xda, 0x09, 0xbe, 0xcf, 0x59, - 0x7c, 0x07, 0x23, 0x68, 0x95, 0x22, 0x01, 0x52, 0xa3,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8f, 0x76, 0xa0, 0x71, 0x41, 0x27, 0x39, 0x33, 0x51, 0xd3, 0x44, - 0x70, 0x09, 0x30, 0xc8, 0xc5, 0xe3, 0x09, 0x0f, 0xdf, 0x0c, 0x86, 0x8b, 0xf4, 0x55, 0x17, 0xea, - 0x93, 0x35, 0x70, 0xee, 0x5a, 0x6d, 0x28, 0x74, 0x08, 0x8d, 0x94, 0x73, 0x21, 0xed, 0x5c, 0x39, - 0x5c, 0xbf, 0x87, 0x7a, 0xfa, 0x4b, 0xe9, 0xcd, 0x8d, 0x23, 0x1a, 0x10, 0x50, 0xe8, 0x3c, 0x49, - 0x19, 0x15, 0xcc, 0xa4, 0x62, 0x69, 0xa0, 0xe6, 0x25, 0x57, 0xbb, 0xfe, 0xcb, 0x59, 0x29, 0x7c, - 0x39, 0xc1, 0x0f, 0xd0, 0x39, 0x61, 0x42, 0x4c, 0x1c, 0x15, 0x1f, 0xf6, 0x09, 0xee, 0x40, 0x23, - 0x8a, 0x47, 0xec, 0x52, 0xa9, 0xa8, 0x13, 0x4d, 0x04, 0xdb, 0xb0, 0xa5, 0x3d, 0x18, 0x4c, 0xf2, - 0xa9, 0x49, 0x76, 0xf0, 0x10, 0x76, 0x4e, 0x59, 0x3a, 0x8d, 0x62, 0x9f, 0xff, 0xee, 0xa1, 0x0d, - 0x7e, 0xaf, 0xc2, 0xa6, 0xbc, 0xf9, 0x51, 0xf3, 0xf2, 0xb9, 0x9f, 0x97, 0xdb, 0x36, 0x2f, 0xbe, - 0xa2, 0x9e, 0x4c, 0x50, 0x76, 0x1c, 0x8b, 0xf4, 0xca, 0xa4, 0x69, 0xff, 0x08, 0x60, 0xce, 0x44, - 0x5d, 0x58, 0x79, 0xc3, 0xae, 0x8c, 0x72, 0xf9, 0x77, 0x71, 0x59, 0x7d, 0x51, 0x3b, 0xaa, 0x06, - 0x39, 0x6c, 0xab, 0x00, 0x14, 0x92, 0xfc, 0x5e, 0xbe, 0x7c, 0x40, 0xd2, 0xff, 0xae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e, 0x1e, 0x0c, 0x89, 0x3a, 0x0a, 0x7e, 0xab, 0x42, 0x43, 0xd1, 0xca, 0x24, 0x6f, - 0x86, 0x5a, 0x52, 0x3a, 0x21, 0x78, 0x12, 0x85, 0xd2, 0x89, 0x15, 0xb9, 0x79, 0x6b, 0x6a, 0xd1, - 0x2b, 0x5e, 0x9a, 0x3f, 0x94, 0x9f, 0xd0, 0xab, 0x7c, 0x3a, 0x34, 0xeb, 0x44, 0x9d, 0xb8, 0x2c, - 0xa9, 0x47, 0x5c, 0xc6, 0xca, 0x75, 0xbd, 0x36, 0x58, 0x52, 0x0e, 0x0a, 0x05, 0x54, 0x67, 0x7a, - 0x8a, 0xcc, 0x19, 0xf3, 0x57, 0xd7, 0xaa, 0x1a, 0x74, 0x9a, 0x18, 0x36, 0x95, 0x4b, 0xf7, 0xff, - 0x09, 0x00, 0x00, 0xff, 0xff, 0x66, 0xf6, 0x44, 0x4e, 0x92, 0x11, 0x00, 0x00, + proto.RegisterType((*DepositToRewardingFund)(nil), "iproto.DepositToRewardingFund") + proto.RegisterType((*ClaimFromRewardingFund)(nil), "iproto.ClaimFromRewardingFund") + proto.RegisterType((*SetReward)(nil), "iproto.SetReward") + proto.RegisterType((*GrantReward)(nil), "iproto.GrantReward") + proto.RegisterEnum("iproto.RewardType", RewardType_name, RewardType_value) +} + +func init() { proto.RegisterFile("action.proto", fileDescriptor_action_7c3e570acfb303ca) } + +var fileDescriptor_action_7c3e570acfb303ca = []byte{ + // 1583 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x58, 0xcb, 0x6f, 0xdb, 0x46, + 0x13, 0x97, 0x64, 0x49, 0xb6, 0x46, 0x7e, 0xc8, 0x6b, 0x7f, 0x0e, 0xed, 0x04, 0x89, 0x43, 0x7c, + 0xf8, 0x60, 0x18, 0x5f, 0x95, 0x36, 0x41, 0x13, 0xa3, 0x28, 0xda, 0x24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0x9a, 0xf2, 0x0f, 0x11, 0xf7, 0xcf, 0x2a, + 0xb4, 0x30, 0xf1, 0x49, 0x10, 0xf1, 0x29, 0xba, 0x0d, 0xed, 0x98, 0xb0, 0x34, 0x0e, 0x5f, 0x89, + 0x6f, 0x02, 0xf9, 0x8d, 0x65, 0xb2, 0xc4, 0x94, 0x62, 0x1e, 0x4b, 0x13, 0x3d, 0x96, 0x25, 0xc5, + 0xe7, 0x9a, 0xe7, 0xb3, 0x9e, 0x97, 0x9c, 0xe9, 0x7f, 0x39, 0x14, 0xc9, 0x75, 0x8e, 0xbc, 0x64, + 0x9f, 0x86, 0x49, 0x3a, 0x21, 0x43, 0xfd, 0x89, 0x6e, 0xb0, 0xf8, 0x52, 0xa0, 0xff, 0x68, 0xd0, + 0x4b, 0x41, 0x43, 0x2e, 0x05, 0x39, 0x36, 0xba, 0x0b, 0xf5, 0x31, 0x1d, 0x25, 0x4e, 0x53, 0x7c, + 0x05, 0x2d, 0x69, 0x4f, 0x5f, 0xd0, 0x51, 0x7f, 0x80, 0xc5, 0x91, 0xfb, 0x7b, 0x15, 0x1a, 0x82, + 0x16, 0x26, 0x59, 0x3b, 0x86, 0x26, 0xb9, 0x13, 0x8c, 0x46, 0x81, 0xcf, 0x9d, 0x98, 0xe3, 0x5f, + 0x26, 0x92, 0x2a, 0xfb, 0x97, 0x83, 0x9b, 0x3f, 0xe0, 0x2d, 0xe6, 0x65, 0x3a, 0x19, 0xa8, 0x75, + 0xab, 0x8e, 0x4d, 0x16, 0xbf, 0x87, 0x5d, 0x84, 0xc2, 0x75, 0xb9, 0x56, 0x69, 0x92, 0x0f, 0x52, + 0x01, 0x14, 0x67, 0x72, 0xca, 0x66, 0x8c, 0xec, 0xab, 0x74, 0x5e, 0x2c, 0x02, 0xea, 0xab, 0xf4, + 0x00, 0x36, 0xca, 0x8b, 0xf2, 0xca, 0x6f, 0x5f, 0x6d, 0x75, 0xcd, 0xf8, 0x6f, 0xe6, 0x00, 0x36, + 0xca, 0x0b, 0xf0, 0x5a, 0x5a, 0x7e, 0x84, 0xd6, 0xb4, 0xf2, 0xae, 0x23, 0x88, 0xfe, 0x07, 0x75, + 0x76, 0x19, 0x11, 0x11, 0xc8, 0xe5, 0x6c, 0x26, 0x4a, 0x4d, 0x27, 0x97, 0x11, 0xc1, 0xe2, 0xdc, + 0xfd, 0x14, 0xda, 0x46, 0x95, 0x4e, 0xc5, 0xaa, 0xb3, 0xc5, 0x76, 0x5d, 0x80, 0x8c, 0x87, 0x5a, + 0xd0, 0x10, 0x43, 0xa0, 0x53, 0xe1, 0x8f, 0x87, 0x11, 0xf5, 0xcf, 0x3a, 0xd5, 0x41, 0x53, 0xc8, + 0x3e, 0xf8, 0x27, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x2d, 0x53, 0x39, 0xfa, 0x13, 0x00, 0x00, } diff --git a/proto/action.proto b/proto/action.proto index 0526e18ec2..2ab0b7f19e 100644 --- a/proto/action.proto +++ b/proto/action.proto @@ -162,6 +162,12 @@ message ActionPb { PlumFinalizeExit plumFinalizeExit = 25; PlumSettleDepositPb plumSettleDeposit = 26; PlumTransferPb plumTransfer = 27; + + // Rewarding protocol actions + DepositToRewardingFund depositToRewardingFund = 30; + ClaimFromRewardingFund claimFromRewardingFund = 31; + SetReward setReward = 32; + GrantReward grantReward = 33; } } @@ -183,3 +189,33 @@ message LogPb { bytes blockHash = 6; uint32 index = 7; } + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// BELOW ARE DEFINITIONS FOR BLOCK PRODUCER PROTOCOL +//////////////////////////////////////////////////////////////////////////////////////////////////// + +message DepositToRewardingFund { + bytes amount = 1; + bytes data = 2; +} + +message ClaimFromRewardingFund { + bytes amount = 1; + bytes data = 2; +} + +enum RewardType { + Block = 0; + Epoch = 1; +} + +message SetReward { + bytes amount = 1; + bytes data = 2; + RewardType type = 3; +} + +message GrantReward { + RewardType type = 1; +} diff --git a/proto/blockchain.pb.go b/proto/blockchain.pb.go index 80e0ba0717..de70348a4e 100644 --- a/proto/blockchain.pb.go +++ b/proto/blockchain.pb.go @@ -44,10 +44,10 @@ func (ConsensusPb_ConsensusMessageType) EnumDescriptor() ([]byte, []int) { // header of a block type BlockHeaderPb struct { - Version uint32 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"` - ChainID uint32 `protobuf:"varint,2,opt,name=chainID" json:"chainID,omitempty"` - Height uint64 `protobuf:"varint,3,opt,name=height" json:"height,omitempty"` - Timestamp *timestamp.Timestamp `protobuf:"bytes,4,opt,name=timestamp" json:"timestamp,omitempty"` + Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` + ChainID uint32 `protobuf:"varint,2,opt,name=chainID,proto3" json:"chainID,omitempty"` + Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"` + Timestamp *timestamp.Timestamp `protobuf:"bytes,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` PrevBlockHash []byte `protobuf:"bytes,5,opt,name=prevBlockHash,proto3" json:"prevBlockHash,omitempty"` TxRoot []byte `protobuf:"bytes,6,opt,name=txRoot,proto3" json:"txRoot,omitempty"` StateRoot []byte `protobuf:"bytes,7,opt,name=stateRoot,proto3" json:"stateRoot,omitempty"` @@ -171,8 +171,8 @@ func (m *BlockHeaderPb) GetPubkey() []byte { // footer of a block type BlockFooterPb struct { - CommitTimestamp int64 `protobuf:"varint,1,opt,name=CommitTimestamp" json:"CommitTimestamp,omitempty"` - Endorsements *EndorsementSet `protobuf:"bytes,2,opt,name=endorsements" json:"endorsements,omitempty"` + CommitTimestamp int64 `protobuf:"varint,1,opt,name=CommitTimestamp,proto3" json:"CommitTimestamp,omitempty"` + Endorsements *EndorsementSet `protobuf:"bytes,2,opt,name=endorsements,proto3" json:"endorsements,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -219,9 +219,9 @@ func (m *BlockFooterPb) GetEndorsements() *EndorsementSet { // block consists of header followed by transactions // hash of current block can be computed from header hence not stored type BlockPb struct { - Header *BlockHeaderPb `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"` - Actions []*ActionPb `protobuf:"bytes,2,rep,name=actions" json:"actions,omitempty"` - Footer *BlockFooterPb `protobuf:"bytes,3,opt,name=footer" json:"footer,omitempty"` + Header *BlockHeaderPb `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` + Actions []*ActionPb `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"` + Footer *BlockFooterPb `protobuf:"bytes,3,opt,name=footer,proto3" json:"footer,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -274,7 +274,7 @@ func (m *BlockPb) GetFooter() *BlockFooterPb { // Receipts consists of a collection of recepit type Receipts struct { - Receipts []*ReceiptPb `protobuf:"bytes,1,rep,name=receipts" json:"receipts,omitempty"` + Receipts []*ReceiptPb `protobuf:"bytes,1,rep,name=receipts,proto3" json:"receipts,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -313,9 +313,9 @@ func (m *Receipts) GetReceipts() []*ReceiptPb { // index of block raw data file type BlockIndex struct { - Start uint64 `protobuf:"varint,1,opt,name=start" json:"start,omitempty"` - End uint64 `protobuf:"varint,2,opt,name=end" json:"end,omitempty"` - Offset []uint32 `protobuf:"varint,3,rep,packed,name=offset" json:"offset,omitempty"` + Start uint64 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"` + End uint64 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"` + Offset []uint32 `protobuf:"varint,3,rep,packed,name=offset,proto3" json:"offset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -367,8 +367,8 @@ func (m *BlockIndex) GetOffset() []uint32 { } type BlockSync struct { - Start uint64 `protobuf:"varint,2,opt,name=start" json:"start,omitempty"` - End uint64 `protobuf:"varint,3,opt,name=end" json:"end,omitempty"` + Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + End uint64 `protobuf:"varint,3,opt,name=end,proto3" json:"end,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -415,7 +415,7 @@ func (m *BlockSync) GetEnd() uint64 { // block container // used to send old/existing blocks in block sync type BlockContainer struct { - Block *BlockPb `protobuf:"bytes,1,opt,name=block" json:"block,omitempty"` + Block *BlockPb `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -453,10 +453,10 @@ func (m *BlockContainer) GetBlock() *BlockPb { } type ConsensusPb struct { - Height uint64 `protobuf:"varint,1,opt,name=height" json:"height,omitempty"` - Round uint32 `protobuf:"varint,2,opt,name=round" json:"round,omitempty"` - Type ConsensusPb_ConsensusMessageType `protobuf:"varint,3,opt,name=type,enum=iproto.ConsensusPb_ConsensusMessageType" json:"type,omitempty"` - Timestamp *timestamp.Timestamp `protobuf:"bytes,4,opt,name=timestamp" json:"timestamp,omitempty"` + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Round uint32 `protobuf:"varint,2,opt,name=round,proto3" json:"round,omitempty"` + Type ConsensusPb_ConsensusMessageType `protobuf:"varint,3,opt,name=type,proto3,enum=iproto.ConsensusPb_ConsensusMessageType" json:"type,omitempty"` + Timestamp *timestamp.Timestamp `protobuf:"bytes,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` Data []byte `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -524,11 +524,11 @@ func (m *ConsensusPb) GetData() []byte { // Candidates and list of candidates type Candidate struct { - Address string `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Votes []byte `protobuf:"bytes,2,opt,name=votes,proto3" json:"votes,omitempty"` PubKey []byte `protobuf:"bytes,3,opt,name=pubKey,proto3" json:"pubKey,omitempty"` - CreationHeight uint64 `protobuf:"varint,4,opt,name=creationHeight" json:"creationHeight,omitempty"` - LastUpdateHeight uint64 `protobuf:"varint,5,opt,name=lastUpdateHeight" json:"lastUpdateHeight,omitempty"` + CreationHeight uint64 `protobuf:"varint,4,opt,name=creationHeight,proto3" json:"creationHeight,omitempty"` + LastUpdateHeight uint64 `protobuf:"varint,5,opt,name=lastUpdateHeight,proto3" json:"lastUpdateHeight,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -594,7 +594,7 @@ func (m *Candidate) GetLastUpdateHeight() uint64 { } type CandidateList struct { - Candidates []*Candidate `protobuf:"bytes,1,rep,name=candidates" json:"candidates,omitempty"` + Candidates []*Candidate `protobuf:"bytes,1,rep,name=candidates,proto3" json:"candidates,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` diff --git a/proto/endorsement.pb.go b/proto/endorsement.pb.go index d203dc68d6..a121303d1d 100644 --- a/proto/endorsement.pb.go +++ b/proto/endorsement.pb.go @@ -46,13 +46,13 @@ func (Endorsement_ConsensusVoteTopic) EnumDescriptor() ([]byte, []int) { // corresponding to prepare and pre-prepare phase in view change protocol type Endorsement struct { - Height uint64 `protobuf:"varint,1,opt,name=height" json:"height,omitempty"` - Round uint32 `protobuf:"varint,2,opt,name=round" json:"round,omitempty"` + Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Round uint32 `protobuf:"varint,2,opt,name=round,proto3" json:"round,omitempty"` BlockHash []byte `protobuf:"bytes,3,opt,name=blockHash,proto3" json:"blockHash,omitempty"` - Topic Endorsement_ConsensusVoteTopic `protobuf:"varint,4,opt,name=topic,enum=iproto.Endorsement_ConsensusVoteTopic" json:"topic,omitempty"` - Endorser string `protobuf:"bytes,5,opt,name=endorser" json:"endorser,omitempty"` + Topic Endorsement_ConsensusVoteTopic `protobuf:"varint,4,opt,name=topic,proto3,enum=iproto.Endorsement_ConsensusVoteTopic" json:"topic,omitempty"` + Endorser string `protobuf:"bytes,5,opt,name=endorser,proto3" json:"endorser,omitempty"` EndorserPubKey []byte `protobuf:"bytes,6,opt,name=endorserPubKey,proto3" json:"endorserPubKey,omitempty"` - Decision bool `protobuf:"varint,7,opt,name=decision" json:"decision,omitempty"` + Decision bool `protobuf:"varint,7,opt,name=decision,proto3" json:"decision,omitempty"` Signature []byte `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -141,8 +141,8 @@ func (m *Endorsement) GetSignature() []byte { type EndorsementSet struct { BlockHash []byte `protobuf:"bytes,1,opt,name=blockHash,proto3" json:"blockHash,omitempty"` - Round uint32 `protobuf:"varint,2,opt,name=round" json:"round,omitempty"` - Endorsements []*Endorsement `protobuf:"bytes,3,rep,name=endorsements" json:"endorsements,omitempty"` + Round uint32 `protobuf:"varint,2,opt,name=round,proto3" json:"round,omitempty"` + Endorsements []*Endorsement `protobuf:"bytes,3,rep,name=endorsements,proto3" json:"endorsements,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` diff --git a/proto/state.pb.go b/proto/state.pb.go index 1211b205ce..19e4f6a9fb 100644 --- a/proto/state.pb.go +++ b/proto/state.pb.go @@ -20,13 +20,13 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type AccountPb struct { // used by state-based model - Nonce uint64 `protobuf:"varint,1,opt,name=nonce" json:"nonce,omitempty"` + Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"` Balance []byte `protobuf:"bytes,2,opt,name=balance,proto3" json:"balance,omitempty"` Root []byte `protobuf:"bytes,3,opt,name=root,proto3" json:"root,omitempty"` CodeHash []byte `protobuf:"bytes,4,opt,name=codeHash,proto3" json:"codeHash,omitempty"` - IsCandidate bool `protobuf:"varint,5,opt,name=isCandidate" json:"isCandidate,omitempty"` + IsCandidate bool `protobuf:"varint,5,opt,name=isCandidate,proto3" json:"isCandidate,omitempty"` VotingWeight []byte `protobuf:"bytes,6,opt,name=votingWeight,proto3" json:"votingWeight,omitempty"` - Votee string `protobuf:"bytes,7,opt,name=votee" json:"votee,omitempty"` + Votee string `protobuf:"bytes,7,opt,name=votee,proto3" json:"votee,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` diff --git a/state/factory/factory_test.go b/state/factory/factory_test.go index ef053793c4..6f1d27d588 100644 --- a/state/factory/factory_test.go +++ b/state/factory/factory_test.go @@ -268,7 +268,7 @@ func TestCandidates(t *testing.T) { gasLimit := uint64(1000000) ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -298,7 +298,7 @@ func TestCandidates(t *testing.T) { zeroGasLimit := uint64(0) zctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &zeroGasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -936,7 +936,7 @@ func TestUnvote(t *testing.T) { gasLimit := uint64(10000000) ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: testutil.EnableGasCharge, }) @@ -1196,7 +1196,7 @@ func benchRunAction(db db.KVStore, b *testing.B) { b.StartTimer() zctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{ - ProducerAddr: testaddress.Addrinfo["producer"].Bech32(), + Producer: testaddress.Addrinfo["producer"], GasLimit: &gasLimit, EnableGasCharge: false, }) diff --git a/state/factory/statetx.go b/state/factory/statetx.go index ca57409941..386d43cf55 100644 --- a/state/factory/statetx.go +++ b/state/factory/statetx.go @@ -9,6 +9,10 @@ package factory import ( "context" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/keypair" + "github.com/iotexproject/iotex-core/pkg/log" + "github.com/pkg/errors" "github.com/iotexproject/iotex-core/action" @@ -64,6 +68,16 @@ func (stx *stateTX) RunActions( // Handle actions receipts := make([]*action.Receipt, 0) for _, elp := range elps { + // Add caller address into the run action context + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss context to run action") + } + callerPKHash := keypair.HashPubKey(elp.SrcPubkey()) + raCtx.Caller = address.New(callerPKHash[:]) + raCtx.ActionHash = elp.Hash() + raCtx.Nonce = elp.Nonce() + ctx = protocol.WithRunActionsCtx(ctx, raCtx) for _, actionHandler := range stx.actionHandlers { receipt, err := actionHandler.Handle(ctx, elp.Action(), stx) if err != nil { diff --git a/state/factory/workingset.go b/state/factory/workingset.go index eeb5502ddf..6047d15c6e 100644 --- a/state/factory/workingset.go +++ b/state/factory/workingset.go @@ -10,6 +10,10 @@ import ( "context" "fmt" + "github.com/iotexproject/iotex-core/address" + "github.com/iotexproject/iotex-core/pkg/keypair" + "github.com/iotexproject/iotex-core/pkg/log" + "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -133,6 +137,16 @@ func (ws *workingSet) RunActions( // Handle actions receipts := make([]*action.Receipt, 0) for _, elp := range elps { + // Add caller address into the run action context + raCtx, ok := protocol.GetRunActionsCtx(ctx) + if !ok { + log.S().Panic("Miss context to run action") + } + callerPKHash := keypair.HashPubKey(elp.SrcPubkey()) + raCtx.Caller = address.New(callerPKHash[:]) + raCtx.ActionHash = elp.Hash() + raCtx.Nonce = elp.Nonce() + ctx = protocol.WithRunActionsCtx(ctx, raCtx) for _, actionHandler := range ws.actionHandlers { receipt, err := actionHandler.Handle(ctx, elp.Action(), ws) if err != nil {