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

fix: Update RPC struct Delegate #21

Merged
merged 20 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v1.21.0
* BREAKING CHANGE: Delegate information is remapped due to RPC changes. The full schema can be found at [link]()
huancheng-trili marked this conversation as resolved.
Show resolved Hide resolved

## v1.19.2
* Update Parisnet hash
* Update protocol history of ghostnet
Expand Down
106 changes: 92 additions & 14 deletions rpc/delegates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import (
"github.com/trilitech/tzgo/tezos"
)

// v021+
type MisbehaviourKind string
type Vote string

const (
MisbehaviourAttestation MisbehaviourKind = "attestation"
MisbehaviourBlock MisbehaviourKind = "block"
MisbehaviourPreattestation MisbehaviourKind = "preattestation"

VoteNay Vote = "nay"
VoteYay Vote = "yay"
VotePass Vote = "pass"
)

// Delegate holds information about an active delegate
type Delegate struct {
// extra info
Expand All @@ -19,23 +33,27 @@ type Delegate struct {
Block string `json:"-"`

// tezos data
Deactivated bool `json:"deactivated"`
Balance int64 `json:"balance,string"`
DelegatedContracts []tezos.Address `json:"delegated_contracts"`
FrozenBalance int64 `json:"frozen_balance,string"`
FrozenBalanceByCycle []CycleBalance `json:"frozen_balance_by_cycle"`
GracePeriod int64 `json:"grace_period"`
StakingBalance int64 `json:"staking_balance,string"`
DelegatedBalance int64 `json:"delegated_balance,string"`
VotingPower Int64orString `json:"voting_power"`

// v012+
Deactivated bool `json:"deactivated"`
GracePeriod int64 `json:"grace_period"`
VotingPower Int64orString `json:"voting_power"`

// -v011
FrozenBalanceByCycle []CycleBalance `json:"frozen_balance_by_cycle"`
FrozenBalance int64 `json:"frozen_balance,string"`
Balance int64 `json:"balance,string"`

// -v020
StakingBalance int64 `json:"staking_balance,string"`
DelegatedContracts []tezos.Address `json:"delegated_contracts"`
DelegatedBalance int64 `json:"delegated_balance,string"`

// v012-v020
FullBalance int64 `json:"full_balance,string"`
FrozenDeposits int64 `json:"frozen_deposits,string"`
CurrentFrozenDeposits int64 `json:"current_frozen_deposits,string"`
FrozenDepositsLimit int64 `json:"frozen_deposits_limit,string"`

// v015+
// v015-v020
ActiveConsensusKey tezos.Address `json:"active_consensus_key"`
PendingConsensusKeys []CycleKey `json:"pending_consensus_keys"`

Expand All @@ -44,14 +62,74 @@ type Delegate struct {
Amount int64 `json:"amount,string"`
Level LevelInfo `json:"level"`
} `json:"min_delegated_in_current_cycle"`
StakingDenominator int64 `json:"staking_denominator,string"`

// v019-v020
PendingDenunciations bool `json:"pending_denunciations"`
TotalDelegatedStake int64 `json:"total_delegated_stakem,string"`
StakingDenominator int64 `json:"staking_denominator,string"`
TotalDelegatedStake int64 `json:"total_delegated_stake,string"`

// v021+
IsForbidden bool `json:"is_forbidden"`
Participation struct {
ExpectedCycleActivity int64 `json:"expected_cycle_activity"`
MinimalCycleActivity int64 `json:"minimal_cycle_activity"`
MissedSlots int64 `json:"missed_slots"`
MissedLevels int64 `json:"missed_levels"`
RemainingAllowedMissedSlots int64 `json:"remaining_allowed_missed_slots"`
ExpectedAttestingRewards uint64 `json:"expected_attesting_rewards,string"`
} `json:"participation"`
ActiveStakingParameters StakingParameters `json:"active_staking_parameters"`
PendingStakingParameters []struct {
Cycle int64 `json:"cycle"`
Parameters StakingParameters `json:"parameters"`
} `json:"pending_staking_parameters"`
BakingPower int64 `json:"baking_power,string"`
TotalStaked uint64 `json:"total_staked,string"`
TotalDelegated uint64 `json:"total_delegated,string"`
OwnFullBalance uint64 `json:"own_full_balance,string"`
OwnStaked uint64 `json:"own_staked,string"`
OwnDelegated uint64 `json:"own_delegated,string"`
ExternalStaked uint64 `json:"external_staked,string"`
ExternalDelegated uint64 `json:"external_delegated,string"`
TotalUnstakedPerCycle struct {
Cycle int64 `json:"cycle"`
Deposit uint64 `json:"deposit,string"`
} `json:"total_unstaked_per_cycle"`
Denunciations []struct {
OperationHash tezos.OpHash `json:"operation_hash"`
Rewarded tezos.Address `json:"rewarded"`
Misbehaviour struct {
Level uint64 `json:"level"`
Round int64 `json:"round"`
Kind MisbehaviourKind `json:"kind,string"`
} `json:"misbehaviour"`
} `json:"denunciations"`
EstimatedSharedPendingSlashedAmount uint64 `json:"estimated_shared_pending_slashed_amount,string"`
CurrentVotingPower uint64 `json:"current_voting_power,string"`
VotingInfo struct {
VotingPower int64 `json:"voting_power"`
CurrentBallot Vote `json:"current_ballot"`
CurrentProposals []tezos.ProtocolHash `json:"current_proposals"`
RemainingProposals int64 `json:"remaining_proposals"`
} `json:"voting_info"`
ConsensusKey struct {
Active struct {
Pkh tezos.Address `json:"pkh"`
Pk tezos.Key `json:"pk"`
} `json:"active"`
Pendings []CycleKey `json:"pendings"`
} `json:"consensus_key"`
Stakers []struct {
Staker tezos.Address `json:"staker"`
FrozenDeposit uint64 `json:"frozen_deposit,string"`
} `json:"stakers"`
Delegators []tezos.Address `json:"delegators"`
}

type CycleKey struct {
Cycle int64 `json:"cycle"`
Pkh tezos.Address `json:"pkh"`
Pk tezos.Key `json:"pk"`
}

type CycleBalance struct {
Expand Down
11 changes: 10 additions & 1 deletion rpc/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ type FrozenDeposit struct {

// GetUnstakedFrozenDeposits returns a delegate's unstaked frozen deposits
func (c *Client) GetUnstakedFrozenDeposits(ctx context.Context, addr tezos.Address, id BlockID) ([]FrozenDeposit, error) {
u := fmt.Sprintf("chains/main/blocks/%s/context/delegates/%s/unstaked_frozen_deposits", id, addr)
p, err := c.GetParams(ctx, id)
if err != nil {
return nil, err
}
resource := "unstaked_frozen_deposits"
if p.Version >= 21 {
resource = "total_unstaked_per_cycle"
}

u := fmt.Sprintf("chains/main/blocks/%s/context/delegates/%s/%s", id, addr, resource)
list := make([]FrozenDeposit, 0, 7)
if err := c.Get(ctx, u, &list); err != nil {
return nil, err
Expand Down
35 changes: 8 additions & 27 deletions tezos/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,32 @@ var (
// either overwrite this default or set custom params per operation using
// op.WithParams().
DefaultParams = (&Params{
MinimalBlockDelay: 10 * time.Second,
MinimalBlockDelay: 8 * time.Second,
CostPerByte: 250,
OriginationSize: 257,
HardGasLimitPerOperation: 1040000,
HardGasLimitPerBlock: 1733333,
HardGasLimitPerBlock: 1386666,
HardStorageLimitPerOperation: 60000,
MaxOperationDataLength: 32768,
MaxOperationsTTL: 360,
MaxOperationsTTL: 450,
}).
WithChainId(Mainnet).
WithDeployment(Deployments[Mainnet].AtProtocol(ProtoV019))
WithDeployment(Deployments[Mainnet].AtProtocol(ProtoV021))

// GhostnetParams defines the blockchain configuration for Ghostnet testnet.
// To produce compliant transactions, use these defaults in op.WithParams().
GhostnetParams = (&Params{
MinimalBlockDelay: 8 * time.Second,
CostPerByte: 250,
OriginationSize: 257,
HardGasLimitPerOperation: 1040000,
HardGasLimitPerBlock: 1733333,
HardStorageLimitPerOperation: 60000,
MaxOperationDataLength: 32768,
MaxOperationsTTL: 360,
}).
WithChainId(Ghostnet).
WithDeployment(Deployments[Ghostnet].AtProtocol(ProtoV019))

// ParisnetParams defines the blockchain configuration for Paris testnet.
// To produce compliant transactions, use these defaults in op.WithParams().
ParisnetParams = (&Params{
MinimalBlockDelay: 5 * time.Second,
CostPerByte: 250,
OriginationSize: 257,
HardGasLimitPerOperation: 1040000,
HardGasLimitPerBlock: 1733333,
HardGasLimitPerBlock: 1386666,
HardStorageLimitPerOperation: 60000,
MaxOperationDataLength: 32768,
MaxOperationsTTL: 360,
MaxOperationsTTL: 450,
}).
WithChainId(Parisnet).
WithDeployment(Deployments[Parisnet].AtProtocol(ProtoV019))
WithChainId(Ghostnet).
WithDeployment(Deployments[Ghostnet].AtProtocol(ProtoV021))
)

// Params contains a subset of protocol configuration settings that are relevant
Expand Down Expand Up @@ -111,10 +96,6 @@ func (p *Params) WithChainId(id ChainIdHash) *Params {
p.Network = "Mainnet"
case Ghostnet:
p.Network = "Ghostnet"
case Parisnet:
p.Network = "Parisnet"
case ParisCnet:
p.Network = "ParisCnet"
}
}
return p
Expand Down
28 changes: 10 additions & 18 deletions tezos/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
ProtoV018 = MustParseProtocolHash("ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH")
ProtoV019 = MustParseProtocolHash("PtParisBxoLz5gzMmn3d9WBQNoPSZakgnkMC2VNuQ3KXfUtUQeZ")
ProtoV020 = MustParseProtocolHash("PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi")
ProtoV021 = MustParseProtocolHash("PtQenaB1PqFEfTe2og7bZTaPvMw2CxRyDFEwWNj3GiWp9ba4bJd")

// aliases
PtAthens = ProtoV004
Expand All @@ -48,11 +49,10 @@ var (
Proxford = ProtoV018
PtParisB = ProtoV019
PsParisC = ProtoV020
PtQenaB1 = ProtoV021

Mainnet = MustParseChainIdHash("NetXdQprcVkpaWU")
Ghostnet = MustParseChainIdHash("NetXnHfVqm9iesp")
Parisnet = MustParseChainIdHash("NetXR64bNAYkP4S")
ParisCnet = MustParseChainIdHash("NetXXWAHLEvre9b")
Mainnet = MustParseChainIdHash("NetXdQprcVkpaWU")
Ghostnet = MustParseChainIdHash("NetXnHfVqm9iesp")

versionsMtx = sync.RWMutex{}
Versions = map[ProtocolHash]int{
Expand All @@ -78,7 +78,8 @@ var (
ProtoV018: 18,
ProtoV019: 19,
ProtoV020: 20,
ProtoAlpha: 21,
ProtoV021: 21,
ProtoAlpha: 22,
}

Deployments = map[ChainIdHash]ProtocolHistory{
Expand All @@ -104,7 +105,8 @@ var (
{PtNairobi, 0, 3760129, 5070848, 623, 5, 16384, 1024}, // v17
{Proxford, 0, 5070849, 5726208, 703, 5, 16384, 1024}, // v18
{PtParisB, 0, 5726209, 5898240, 743, 2, 24576, 24576}, // v19
{PsParisC, 0, 5898241, -1, 750, 2, 24576, 24576}, // v19
{PsParisC, 0, 5898241, -1, 750, 2, 24576, 24576}, // v20
{PtQenaB1, 0, 5898241, -1, 750, 2, 30720, 30720}, // v21
},
Ghostnet: {
{ProtoGenesis, 0, 0, 0, 0, 3, 4096, 256}, // 0
Expand All @@ -118,18 +120,8 @@ var (
{PtNairobi, 0, 2957313, 5316608, 625, 3, 8192, 512}, // v17
{Proxford, 0, 5316609, 6422528, 913, 3, 8192, 512}, // v18
{PtParisB, 0, 6422529, 6729728, 1048, 2, 12288, 12288}, // v19
{PsParisC, 0, 6729729, -1, 1073, 2, 12288, 12288}, // v19
},
Parisnet: {
{ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0
{ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0
{Proxford, 2, 2, 8192, 0, 3, 8192, 512}, // v18
{PtParisB, 0, 8193, -1, 1, 2, 12288, 12288}, // v19
},
ParisCnet: {
{ProtoGenesis, 0, 0, 0, 0, 3, 8192, 512}, // 0
{ProtoBootstrap, 0, 1, 1, 0, 3, 8192, 512}, // 0
{PsParisC, 2, 2, -1, 0, 2, 128, 128}, // v19
{PsParisC, 0, 6729729, -1, 1073, 2, 12288, 12288}, // v20
{PtQenaB1, 0, 5898241, -1, 750, 2, 30720, 30720}, // v21
},
}
)
Expand Down