Skip to content

Commit

Permalink
Merge pull request #370 from oasisprotocol/mitjat/cobalt-richer-staki…
Browse files Browse the repository at this point in the history
…ng-events

Cobalt: Support 2 versions of escrow events. Disable non-negativity check for escrow values.
  • Loading branch information
mitjat authored Apr 11, 2023
2 parents 5b1133c + d0bb1b1 commit 239a8fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
8 changes: 5 additions & 3 deletions coreapi/v21.1.1/staking/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ type Event struct {
// AddEscrowEvent is the event emitted when stake is transferred into an escrow
// account.
type AddEscrowEvent struct {
Owner Address `json:"owner"`
Escrow Address `json:"escrow"`
Amount quantity.Quantity `json:"amount"`
Owner Address `json:"owner"`
Escrow Address `json:"escrow"`
Amount quantity.Quantity `json:"amount"`
NewShares quantity.Quantity `json:"new_shares"` // Only emitted at _some_ heights; introduced in oasis-core v21.2.0 mid-Cobalt.
}

// TakeEscrowEvent is the event emitted when stake is taken from an escrow
Expand All @@ -96,6 +97,7 @@ type ReclaimEscrowEvent struct {
Owner Address `json:"owner"`
Escrow Address `json:"escrow"`
Amount quantity.Quantity `json:"amount"`
Shares quantity.Quantity `json:"shares"` // Only emitted at _some_ heights; introduced in oasis-core v21.2.0 mid-Cobalt.
}

// AllowanceChangeEvent is the event emitted when allowance is changed for a beneficiary.
Expand Down
11 changes: 7 additions & 4 deletions storage/migrations/01_consensus.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,13 @@ CREATE TABLE chain.accounts
nonce UINT63 NOT NULL DEFAULT 0,

-- Escrow Account
escrow_balance_active UINT_NUMERIC NOT NULL DEFAULT 0,
escrow_total_shares_active UINT_NUMERIC NOT NULL DEFAULT 0,
escrow_balance_debonding UINT_NUMERIC NOT NULL DEFAULT 0,
escrow_total_shares_debonding UINT_NUMERIC NOT NULL DEFAULT 0
-- TODO: Use UINT_NUMERIC for the next four columns. Their values should always be >=0;
-- however in Cobalt, the emitted events didn't allow perfect tracking of shares, so
-- the indexer can arrive at negative values (https://github.com/oasisprotocol/oasis-indexer/pull/370).
escrow_balance_active NUMERIC(1000,0) NOT NULL DEFAULT 0,
escrow_total_shares_active NUMERIC(1000,0) NOT NULL DEFAULT 0,
escrow_balance_debonding NUMERIC(1000,0) NOT NULL DEFAULT 0,
escrow_total_shares_debonding NUMERIC(1000,0) NOT NULL DEFAULT 0

-- TODO: Track commission schedule and staking accumulator.
);
Expand Down
22 changes: 6 additions & 16 deletions storage/oasis/nodeapi/cobalt/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,9 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
switch {
case e.Staking.Escrow.Add != nil:
ret = nodeapi.Event{
StakingAddEscrow: &nodeapi.AddEscrowEvent{
Owner: e.Staking.Escrow.Add.Owner,
Escrow: e.Staking.Escrow.Add.Escrow,
Amount: e.Staking.Escrow.Add.Amount,
NewShares: quantity.Quantity{}, // NOTE: not available in the Cobalt API
},
Body: e.Staking.Escrow.Add,
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
StakingAddEscrow: (*nodeapi.AddEscrowEvent)(e.Staking.Escrow.Add),
Body: e.Staking.Escrow.Add,
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
}
case e.Staking.Escrow.Take != nil:
ret = nodeapi.Event{
Expand All @@ -200,14 +195,9 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
}
case e.Staking.Escrow.Reclaim != nil:
ret = nodeapi.Event{
StakingReclaimEscrow: &nodeapi.ReclaimEscrowEvent{
Owner: e.Staking.Escrow.Reclaim.Owner,
Escrow: e.Staking.Escrow.Reclaim.Escrow,
Amount: e.Staking.Escrow.Reclaim.Amount,
Shares: quantity.Quantity{}, // NOTE: not available in the Cobalt API
},
Body: e.Staking.Escrow.Reclaim,
Type: apiTypes.ConsensusEventTypeStakingEscrowReclaim,
StakingReclaimEscrow: (*nodeapi.ReclaimEscrowEvent)(e.Staking.Escrow.Reclaim),
Body: e.Staking.Escrow.Reclaim,
Type: apiTypes.ConsensusEventTypeStakingEscrowReclaim,
}
// NOTE: There is no Staking.Escrow.DebondingStart event in Cobalt.
}
Expand Down

0 comments on commit 239a8fa

Please sign in to comment.