Skip to content

Commit

Permalink
Add a memorial transfer into the first block (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjshen14 committed Apr 21, 2019
1 parent ac9180f commit a4308fc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
8 changes: 4 additions & 4 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var (
{
11,
5,
4,
5,
},
}

Expand Down Expand Up @@ -283,7 +283,7 @@ var (
1,
"lifeLongDelegates",
4,
15,
16,
5,
iotextypes.EpochData{
Num: 1,
Expand All @@ -296,8 +296,8 @@ var (
5,
"governanceChainCommittee",
4,
15,
15,
16,
16,
iotextypes.EpochData{
Num: 1,
Height: 1,
Expand Down
37 changes: 37 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,21 @@ func (bc *blockchain) pickAndRunActions(ctx context.Context, actionMap map[strin
executedActions = append(executedActions, grant)
}

if raCtx.BlockHeight == 1 {
tsf, err := bc.createMemorialTransfer(raCtx.Producer.String(), raCtx.ActionGasLimit)
if err != nil {
return hash.ZeroHash256, nil, nil, err
}
receipt, err = ws.RunAction(raCtx, tsf)
if err != nil {
return hash.ZeroHash256, nil, nil, err
}
if receipt != nil {
receipts = append(receipts, receipt)
}
executedActions = append(executedActions, tsf)
}

blockMtc.WithLabelValues("gasConsumed").Set(float64(bc.config.Genesis.BlockGasLimit - raCtx.GasLimit))

return ws.UpdateBlockLevelInfo(raCtx.BlockHeight), receipts, executedActions, nil
Expand Down Expand Up @@ -1275,6 +1290,28 @@ func (bc *blockchain) createGrantRewardAction(rewardType int, height uint64) (ac
return action.Sign(envelope, sk)
}

func (bc *blockchain) createMemorialTransfer(recipient string, gasLimit uint64) (action.SealedEnvelope, error) {
tsf, err := action.NewTransfer(
0,
big.NewInt(0),
recipient,
[]byte("rcqgjsxfdxzszztpydzlzclplz://U2FsdGVkX19E4w2QggPJ/6N38eCU4YTvONyK8A5jZ1XIoQDC2lZBHGe9dDFkN6ToJqaAxcPx6JEzOv/yiVAl6a+Pym+I02BvleW2mcKuMV6tWHRHTnJuu981x2XP2oW9"),
gasLimit,
big.NewInt(0),
)
if err != nil {
return action.SealedEnvelope{}, err
}
eb := action.EnvelopeBuilder{}
envelope := eb.SetNonce(tsf.Nonce()).
SetGasPrice(tsf.GasPrice()).
SetGasLimit(tsf.GasLimit()).
SetAction(tsf).
Build()
sk := bc.config.ProducerPrivateKey()
return action.Sign(envelope, sk)
}

func (bc *blockchain) createGenesisStates(ws factory.WorkingSet) error {
if bc.registry == nil {
// TODO: return nil to avoid test cases to blame on missing rewarding protocol
Expand Down
6 changes: 3 additions & 3 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ func TestBlockchain_MintNewBlock(t *testing.T) {
testutil.TimestampNow(),
)
require.NoError(t, err)
require.Equal(t, 2, len(blk.Actions))
require.Equal(t, 1, len(blk.Receipts))
require.Equal(t, 3, len(blk.Actions))
require.Equal(t, 2, len(blk.Receipts))
var gasConsumed uint64
for _, receipt := range blk.Receipts {
gasConsumed += receipt.GasConsumed
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestLoadBlockchainfromDB(t *testing.T) {
require.Nil(addTestingTsfBlocks(bc))
err = bc.Stop(ctx)
require.NoError(err)
require.Equal(22, ms.Counter())
require.Equal(23, ms.Counter())

// Load a blockchain from DB
sf, err = factory.NewFactory(cfg, factory.DefaultTrieOption())
Expand Down
2 changes: 1 addition & 1 deletion consensus/scheme/rolldpos/rolldpos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func TestRollDPoSConsensus(t *testing.T) {
blockchain.RegistryOption(&registry),
)
require.NoError(t, registry.Register(vote.ProtocolID, vote.NewProtocol(chain)))
chain.Validator().AddActionEnvelopeValidators(protocol.NewGenericValidator(chain, 0))
chain.Validator().AddActionEnvelopeValidators(protocol.NewGenericValidator(chain, cfg.Genesis.ActionGasLimit))
chain.Validator().AddActionValidators(account.NewProtocol())
chains = append(chains, chain)

Expand Down
2 changes: 1 addition & 1 deletion explorer/explorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestExplorerApi(t *testing.T) {
require.Equal(int64(0), stats.Transfers)
require.Equal(int64(0), stats.Votes)
require.Equal(int64(0), stats.Executions)
require.Equal(int64(11), stats.Aps)
require.Equal(int64(12), stats.Aps)

// success
balance, err := svc.GetAddressBalance(ta.Addrinfo["charlie"].String())
Expand Down
9 changes: 7 additions & 2 deletions gasstation/gasstattion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ func TestSuggestGasPrice(t *testing.T) {
testutil.TimestampNow(),
)
require.NoError(t, err)
require.Equal(t, 2, len(blk.Actions))
require.Equal(t, 1, len(blk.Receipts))
if i == 0 {
require.Equal(t, 3, len(blk.Actions))
require.Equal(t, 2, len(blk.Receipts))
} else {
require.Equal(t, 2, len(blk.Actions))
require.Equal(t, 1, len(blk.Receipts))
}
var gasConsumed uint64
for _, receipt := range blk.Receipts {
gasConsumed += receipt.GasConsumed
Expand Down

0 comments on commit a4308fc

Please sign in to comment.