Skip to content

Commit

Permalink
Merge pull request #2935 from oasislabs/andrej/bugfix/more-staking-ev…
Browse files Browse the repository at this point in the history
…ents

staking: Add missing events
  • Loading branch information
abukosek authored May 22, 2020
2 parents 407e098 + 655bfde commit 0df697c
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .buildkite/code.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ steps:
###############
- label: E2E tests
parallelism: 7
timeout_in_minutes: 9
timeout_in_minutes: 11
command:
- .buildkite/scripts/download_e2e_test_artifacts.sh
- .buildkite/scripts/test_e2e.sh
Expand All @@ -254,7 +254,7 @@ steps:
###########################
- label: E2E tests - intel-sgx
parallelism: 5
timeout_in_minutes: 19
timeout_in_minutes: 21
command:
- .buildkite/scripts/download_e2e_test_artifacts.sh
- .buildkite/scripts/test_e2e.sh
Expand Down
Empty file added .changelog/2935.trivial.md
Empty file.
1 change: 1 addition & 0 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ func (mux *abciMux) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverT
Codespace: module,
Code: code,
Log: err.Error(),
Events: ctx.GetEvents(),
GasWanted: int64(ctx.Gas().GasWanted()),
GasUsed: int64(ctx.Gas().GasUsed()),
}
Expand Down
14 changes: 7 additions & 7 deletions go/consensus/tendermint/apps/staking/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ func (app *stakingApplication) disburseFeesVQ(
if err = stakeState.SetAccount(ctx, *proposerEntity, acct); err != nil {
return fmt.Errorf("failed to set next proposer account: %w", err)
}
}

// Emit transfer event.
evt := &staking.TransferEvent{
From: staking.FeeAccumulatorAccountID,
To: *proposerEntity,
Tokens: *nextProposerTotal,
// Emit transfer event.
evt := &staking.TransferEvent{
From: staking.FeeAccumulatorAccountID,
To: *proposerEntity,
Tokens: *nextProposerTotal,
}
ctx.EmitEvent(abciAPI.NewEventBuilder(app.Name()).Attribute(KeyTransfer, cbor.Marshal(evt)))
}
ctx.EmitEvent(abciAPI.NewEventBuilder(app.Name()).Attribute(KeyTransfer, cbor.Marshal(evt)))
}

// Pay the voters.
Expand Down
25 changes: 24 additions & 1 deletion go/consensus/tendermint/apps/staking/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,30 @@ func (sq *stakingQuerier) Accounts(ctx context.Context) ([]signature.PublicKey,
}

func (sq *stakingQuerier) AccountInfo(ctx context.Context, id signature.PublicKey) (*staking.Account, error) {
return sq.state.Account(ctx, id)
switch {
case id.Equal(staking.CommonPoolAccountID):
cp, err := sq.state.CommonPool(ctx)
if err != nil {
return nil, err
}
return &staking.Account{
General: staking.GeneralAccount{
Balance: *cp,
},
}, nil
case id.Equal(staking.FeeAccumulatorAccountID):
fa, err := sq.state.LastBlockFees(ctx)
if err != nil {
return nil, err
}
return &staking.Account{
General: staking.GeneralAccount{
Balance: *fa,
},
}, nil
default:
return sq.state.Account(ctx, id)
}
}

func (sq *stakingQuerier) Delegations(ctx context.Context, id signature.PublicKey) (map[signature.PublicKey]*staking.Delegation, error) {
Expand Down
18 changes: 18 additions & 0 deletions go/consensus/tendermint/apps/staking/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func (s *ImmutableState) Accounts(ctx context.Context) ([]signature.PublicKey, e
}

func (s *ImmutableState) Account(ctx context.Context, id signature.PublicKey) (*staking.Account, error) {
if !id.IsValid() {
return nil, fmt.Errorf("tendermint/staking: invalid account ID")
}

value, err := s.is.Get(ctx, accountKeyFmt.Encode(&id))
if err != nil {
return nil, abciAPI.UnavailableStateError(err)
Expand Down Expand Up @@ -805,6 +809,13 @@ func (s *MutableState) AddRewards(
if err = s.SetDelegation(ctx, id, id, delegation); err != nil {
return fmt.Errorf("tendermint/staking: failed to set delegation: %w", err)
}

ev := cbor.Marshal(&staking.AddEscrowEvent{
Owner: staking.CommonPoolAccountID,
Escrow: id,
Tokens: *com,
})
ctx.EmitEvent(api.NewEventBuilder(AppName).Attribute(KeyAddEscrow, ev))
}

if err = s.SetAccount(ctx, id, ent); err != nil {
Expand Down Expand Up @@ -926,6 +937,13 @@ func (s *MutableState) AddRewardSingleAttenuated(
if err = s.SetDelegation(ctx, account, account, delegation); err != nil {
return fmt.Errorf("tendermint/staking: failed to set delegation: %w", err)
}

ev := cbor.Marshal(&staking.AddEscrowEvent{
Owner: staking.CommonPoolAccountID,
Escrow: account,
Tokens: *com,
})
ctx.EmitEvent(api.NewEventBuilder(AppName).Attribute(KeyAddEscrow, ev))
}

if err = s.SetAccount(ctx, account, ent); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/debond.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *debondImpl) Run(*env.Env) error {
lockupQuery := staking.OwnerQuery{
Height: consensus.HeightLatest,
}
if err := lockupQuery.Owner.UnmarshalHex("5555555555555555555555555555555555555555555555555555555555555555"); err != nil {
if err := lockupQuery.Owner.UnmarshalText([]byte("LQu4ZtFg8OJ0MC4M4QMeUR7Is6Xt4A/CW+PK/7TPiH0=")); err != nil {
return fmt.Errorf("import lockup account ID: %w", err)
}
s.logger.Info("checking balance at beginning")
Expand Down
3 changes: 3 additions & 0 deletions go/staking/api/sanity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (p *ConsensusParameters) SanityCheck() error {
// SanityCheckAccount examines an account's balances.
// Adds the balances to a running total `total`.
func SanityCheckAccount(total *quantity.Quantity, parameters *ConsensusParameters, now epochtime.EpochTime, id signature.PublicKey, acct *Account) error {
if !id.IsValid() {
return fmt.Errorf("staking: sanity check failed: account has invalid ID: %s", id)
}
if !acct.General.Balance.IsValid() {
return fmt.Errorf("staking: sanity check failed: general balance is invalid for account with ID: %s", id)
}
Expand Down
6 changes: 3 additions & 3 deletions tests/fixture-data/debond/staking-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"total_supply": "1000",
"ledger": {
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=": {
"ADoWBAua0sJigqXO82hLaC0dDahZwm8bXQHNj7/xtKQ=": {
"escrow": {
"debonding": {
"balance": "1000",
Expand All @@ -28,8 +28,8 @@
}
},
"debonding_delegations": {
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=": {
"VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVU=": [
"ADoWBAua0sJigqXO82hLaC0dDahZwm8bXQHNj7/xtKQ=": {
"LQu4ZtFg8OJ0MC4M4QMeUR7Is6Xt4A/CW+PK/7TPiH0=": [
{
"shares": "500",
"debond_end": 1
Expand Down

0 comments on commit 0df697c

Please sign in to comment.