Skip to content

Commit

Permalink
Merge pull request #565 from oasisprotocol/mitjat/warn-absent-new-shares
Browse files Browse the repository at this point in the history
analyzer: damask: Warn about incompatibility with slow-sync
  • Loading branch information
mitjat authored Nov 28, 2023
2 parents da6d23a + 698afd9 commit 6b2fe2e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
10 changes: 9 additions & 1 deletion analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,15 @@ func (m *processor) queueEscrows(batch *storage.QueryBatch, data *stakingData) e
owner := e.Owner.String()
escrower := e.Escrow.String()
amount := e.Amount.String()
newShares := e.NewShares.String()
newShares := "0"
if e.NewShares == nil {
m.logger.Warn(
"AddEscrowEvent with a missing `new_shares` field encountered. The absence of that field makes dead reckoning impossible. Skip over old heights with fast-sync to work around the issue.",
"height", data.Height, "owner", owner, "escrower", escrower, "amount", amount,
)
} else {
newShares = e.NewShares.String()
}
batch.Queue(queries.ConsensusDecreaseGeneralBalanceUpsert,
owner,
amount,
Expand Down
13 changes: 9 additions & 4 deletions coreapi/v22.2.11/staking/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ 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"`
NewShares quantity.Quantity `json:"new_shares"`
Owner Address `json:"owner"`
Escrow Address `json:"escrow"`
Amount quantity.Quantity `json:"amount"`
// Originally not a pointer. This field is always present in Damask.
// We made it a pointer because
// - CBOR doesn't care whether it decodes into a Quantity or *Quantity
// - This lets us (ab)use this struct for nexus-internal purposes too,
// where we want to distinguish between "not present" and "present but zero".
NewShares *quantity.Quantity `json:"new_shares"`
}

// EventKind returns a string representation of this event's kind.
Expand Down
11 changes: 8 additions & 3 deletions storage/oasis/nodeapi/cobalt/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ func convertEvent(e txResultsCobalt.Event) nodeapi.Event {
switch {
case e.Staking.Escrow.Add != nil:
ret = nodeapi.Event{
StakingAddEscrow: (*nodeapi.AddEscrowEvent)(e.Staking.Escrow.Add),
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
StakingAddEscrow: &nodeapi.AddEscrowEvent{
Owner: e.Staking.Escrow.Add.Owner,
Escrow: e.Staking.Escrow.Add.Escrow,
Amount: e.Staking.Escrow.Add.Amount,
NewShares: nil, // Only present in a part of Cobalt. Pretend it never exists in Cobalt because we cannot distinguish between 0 and not-present.
},
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
}
case e.Staking.Escrow.Take != nil:
ret = nodeapi.Event{
Expand Down
11 changes: 8 additions & 3 deletions storage/oasis/nodeapi/eden/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,14 @@ func convertEvent(e txResultsEden.Event) nodeapi.Event {
switch {
case e.Staking.Escrow.Add != nil:
ret = nodeapi.Event{
StakingAddEscrow: (*nodeapi.AddEscrowEvent)(e.Staking.Escrow.Add),
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
StakingAddEscrow: &nodeapi.AddEscrowEvent{
Owner: e.Staking.Escrow.Add.Owner,
Escrow: e.Staking.Escrow.Add.Escrow,
Amount: e.Staking.Escrow.Add.Amount,
NewShares: &e.Staking.Escrow.Add.NewShares,
},
RawBody: common.TryAsJSON(e.Staking.Escrow.Add),
Type: apiTypes.ConsensusEventTypeStakingEscrowAdd,
}
case e.Staking.Escrow.Take != nil:
ret = nodeapi.Event{
Expand Down
Binary file modified tests/e2e_regression/rpc-cache/consensus/00000-1.psg.pmt
Binary file not shown.
Binary file modified tests/e2e_regression/rpc-cache/consensus/db.pmt
Binary file not shown.
Binary file modified tests/e2e_regression/rpc-cache/consensus/index.pmt
Binary file not shown.
Binary file modified tests/e2e_regression/rpc-cache/emerald/00000-1.psg.pmt
Binary file not shown.
Binary file modified tests/e2e_regression/rpc-cache/emerald/db.pmt
Binary file not shown.
Binary file modified tests/e2e_regression/rpc-cache/emerald/index.pmt
Binary file not shown.

0 comments on commit 6b2fe2e

Please sign in to comment.