Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to v2 schema #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 76 additions & 26 deletions client/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const (
StakingStatsQueueName string = "staking_stats_queue"
BtcInfoQueueName string = "btc_info_queue"
ConfirmedInfoQueueName string = "confirmed_info_queue"
VerifiedStakingQueueName string = "verified_staking_queue"
PendingStakingQueueName string = "pending_staking_queue"
)

const (
Expand All @@ -18,6 +20,8 @@ const (
StatsEventType EventType = 5
BtcInfoEventType EventType = 6
ConfirmedInfoEventType EventType = 7
VerifiedStakingEventType EventType = 8
PendingStakingEventType EventType = 9
)

// Event schema versions, only increment when the schema changes
Expand All @@ -29,6 +33,8 @@ const (
StatsEventVersion int = 1
BtcInfoEventVersion int = 0
ConfirmedInfoEventVersion int = 0
VerifiedEventVersion int = 0
PendingEventVersion int = 0
)

type EventType int
Expand All @@ -39,18 +45,18 @@ type EventMessage interface {
}

type ActiveStakingEvent struct {
SchemaVersion int `json:"schema_version"`
EventType EventType `json:"event_type"` // always 1. ActiveStakingEventType
StakingTxHashHex string `json:"staking_tx_hash_hex"`
StakerPkHex string `json:"staker_pk_hex"`
FinalityProviderPkHex string `json:"finality_provider_pk_hex"`
StakingValue uint64 `json:"staking_value"`
StakingStartHeight uint64 `json:"staking_start_height"`
StakingStartTimestamp int64 `json:"staking_start_timestamp"`
StakingTimeLock uint64 `json:"staking_timelock"`
StakingOutputIndex uint64 `json:"staking_output_index"`
StakingTxHex string `json:"staking_tx_hex"`
IsOverflow bool `json:"is_overflow"`
SchemaVersion int `json:"schema_version"`
EventType EventType `json:"event_type"` // always 1. ActiveStakingEventType
StakingTxHashHex string `json:"staking_tx_hash_hex"`
StakerBtcPkHex string `json:"staker_btc_pk_hex"`
FinalityProviderBtcPksHex []string `json:"finality_provider_btc_pks_hex"`
StakingValue uint64 `json:"staking_value"`
StakingStartHeight uint64 `json:"staking_start_height"`
StakingStartTimestamp int64 `json:"staking_start_timestamp"`
StakingTimeLock uint64 `json:"staking_timelock"`
StakingOutputIndex uint64 `json:"staking_output_index"`
StakingTxHex string `json:"staking_tx_hex"`
IsOverflow bool `json:"is_overflow"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy-babylonlabs @gusin13 i think we need to review the msg events needed for phase-2.
For example, IsOverflow, StakingStartTimestamp, stakingTimeLock, stakingOutputIndex, and stakingTxHex don’t seem to be necessary.

If I’m not mistaken, we only need the staking transaction hash and its new state. Theoretically, this means we could significantly simplify the current messaging system.

We should align the msg with state changes in the indexer and only emit the fields that needed for performing the stats calculation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm right, needs investigation.
let me check, @jeremy-babylonlabs this pr is not urgent correct as you already have local copy of schema in api-service?

is it ok if we close this pr, will open a new one later once i have clarity on schema.

}

func (e ActiveStakingEvent) GetEventType() EventType {
Expand All @@ -63,8 +69,8 @@ func (e ActiveStakingEvent) GetStakingTxHashHex() string {

func NewActiveStakingEvent(
stakingTxHashHex string,
stakerPkHex string,
finalityProviderPkHex string,
stakerBtcPkHex string,
finalityProviderBtcPksHex []string,
stakingValue uint64,
stakingStartHeight uint64,
stakingStartTimestamp int64,
Expand All @@ -74,18 +80,18 @@ func NewActiveStakingEvent(
isOverflow bool,
) ActiveStakingEvent {
return ActiveStakingEvent{
SchemaVersion: ActiveEventVersion,
EventType: ActiveStakingEventType,
StakingTxHashHex: stakingTxHashHex,
StakerPkHex: stakerPkHex,
FinalityProviderPkHex: finalityProviderPkHex,
StakingValue: stakingValue,
StakingStartHeight: stakingStartHeight,
StakingStartTimestamp: stakingStartTimestamp,
StakingTimeLock: stakingTimeLock,
StakingOutputIndex: stakingOutputIndex,
StakingTxHex: stakingTxHex,
IsOverflow: isOverflow,
SchemaVersion: ActiveEventVersion,
EventType: ActiveStakingEventType,
StakingTxHashHex: stakingTxHashHex,
StakerBtcPkHex: stakerBtcPkHex,
FinalityProviderBtcPksHex: finalityProviderBtcPksHex,
StakingValue: stakingValue,
StakingStartHeight: stakingStartHeight,
StakingStartTimestamp: stakingStartTimestamp,
StakingTimeLock: stakingTimeLock,
StakingOutputIndex: stakingOutputIndex,
StakingTxHex: stakingTxHex,
IsOverflow: isOverflow,
}
}

Expand Down Expand Up @@ -278,3 +284,47 @@ func NewConfirmedInfoEvent(height, tvl uint64) ConfirmedInfoEvent {
Tvl: tvl,
}
}

type VerifiedStakingEvent struct {
SchemaVersion int `json:"schema_version"`
EventType EventType `json:"event_type"` // always 8. VerifiedStakingEventType
StakingTxHashHex string `json:"staking_tx_hash_hex"`
}

func (e VerifiedStakingEvent) GetEventType() EventType {
return VerifiedStakingEventType
}

func (e VerifiedStakingEvent) GetStakingTxHashHex() string {
return e.StakingTxHashHex
}

func NewVerifiedStakingEvent(stakingTxHashHex string) VerifiedStakingEvent {
return VerifiedStakingEvent{
SchemaVersion: VerifiedEventVersion,
EventType: VerifiedStakingEventType,
StakingTxHashHex: stakingTxHashHex,
}
}

type PendingStakingEvent struct {
SchemaVersion int `json:"schema_version"`
EventType EventType `json:"event_type"` // always 9. PendingStakingEventType
StakingTxHashHex string `json:"staking_tx_hash_hex"`
}

func (e PendingStakingEvent) GetEventType() EventType {
return PendingStakingEventType
}

func (e PendingStakingEvent) GetStakingTxHashHex() string {
return e.StakingTxHashHex
}

func NewPendingStakingEvent(stakingTxHashHex string) PendingStakingEvent {
return PendingStakingEvent{
SchemaVersion: PendingEventVersion,
EventType: PendingStakingEventType,
StakingTxHashHex: stakingTxHashHex,
}
}
2 changes: 1 addition & 1 deletion tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func buildActiveNStakingEvents(stakerHash string, numOfEvent int) []*client.Acti
activeStakingEvent := client.NewActiveStakingEvent(
"0x1234567890abcdef"+fmt.Sprint(i),
stakerHash,
"0xabcdef1234567890"+fmt.Sprint(i),
[]string{"0xabcdef1234567890" + fmt.Sprint(i)},
1+uint64(i),
100+uint64(i),
time.Now().Unix(),
Expand Down