Skip to content

Commit c4fc1b9

Browse files
Add validator_weight and delegation_fee to P-Chain staking operation metadata (#249)
* adding validator_weight field to P-chain staking operation metadata * adding delegation_fee to REWARD_VALIDATOR operation * add missing fields to tests * fix: Update golangci-lint config for v1.62+ compatibility Updated .golangci.yml to be compatible with golangci-lint v1.62+: - Removed deprecated skip-dirs-use-default field - Updated forbidigo config to use new structured format (p/msg) - Changed exclude_godoc_examples to exclude-godoc-examples (hyphenated) This fixes the CI linting failures without changing any linting rules. --------- Signed-off-by: Raj Ranjan <rranjan01234@gmail.com> Co-authored-by: Raj Ranjan <rranjan01234@gmail.com>
1 parent b562afb commit c4fc1b9

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

mapper/pchain/tx_parser.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,17 @@ func addValidatorMetadataToStakeOuts(ops *txOps, validator txs.ValidatorTx, star
387387
out.Metadata[MetadataValidatorNodeID] = validator.NodeID().String()
388388
out.Metadata[MetadataStakingStartTime] = uint64(startTime.Unix())
389389
out.Metadata[MetadataStakingEndTime] = uint64(validator.EndTime().Unix())
390+
out.Metadata[MetadataValidatorWeight] = validator.Weight()
390391
out.Metadata[MetadataValidatorRewardsOwner] = getAddressArray(validator.ValidationRewardsOwner().(*secp256k1fx.OutputOwners), hrp)
391392
out.Metadata[MetadataDelegationRewardsOwner] = getAddressArray(validator.DelegationRewardsOwner().(*secp256k1fx.OutputOwners), hrp)
392393
out.Metadata[MetadataSubnetID] = validator.SubnetID().String()
394+
395+
switch v := validator.(type) {
396+
case *txs.AddValidatorTx:
397+
out.Metadata[MetadataDelegationFee] = v.DelegationShares
398+
case *txs.AddPermissionlessValidatorTx:
399+
out.Metadata[MetadataDelegationFee] = v.DelegationShares
400+
}
393401
}
394402
}
395403

@@ -402,6 +410,7 @@ func addDelegatorMetadataToStakeOuts(ops *txOps, delegator txs.DelegatorTx, star
402410
out.Metadata[MetadataValidatorNodeID] = delegator.NodeID().String()
403411
out.Metadata[MetadataStakingStartTime] = uint64(startTime.Unix())
404412
out.Metadata[MetadataStakingEndTime] = uint64(delegator.EndTime().Unix())
413+
out.Metadata[MetadataValidatorWeight] = delegator.Weight()
405414
out.Metadata[MetadataDelegatorRewardsOwner] = getAddressArray(delegator.RewardsOwner().(*secp256k1fx.OutputOwners), hrp)
406415
out.Metadata[MetadataSubnetID] = delegator.SubnetID().String()
407416
}

mapper/pchain/tx_parser_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func TestMapAddValidatorTx(t *testing.T) {
176176
require.Equal(2, cntInputMeta)
177177
require.Zero(cntOutputMeta)
178178
require.Equal(1, cntMetaType)
179+
180+
stakeOutOp := rosettaTransaction.Operations[2]
181+
require.Equal(OpTypeStakeOutput, stakeOutOp.Metadata["type"])
182+
require.Equal(uint64(2000000000), stakeOutOp.Metadata[MetadataValidatorWeight])
183+
require.Equal(uint32(20000), stakeOutOp.Metadata[MetadataDelegationFee])
179184
}
180185

181186
func TestMapAddPermissionlessValidatorTx(t *testing.T) {
@@ -209,6 +214,11 @@ func TestMapAddPermissionlessValidatorTx(t *testing.T) {
209214
require.Equal(2, cntInputMeta)
210215
require.Zero(cntOutputMeta)
211216
require.Equal(1, cntMetaType)
217+
218+
stakeOutOp := rosettaTransaction.Operations[2]
219+
require.Equal(OpTypeStakeOutput, stakeOutOp.Metadata["type"])
220+
require.Equal(uint64(2000000000), stakeOutOp.Metadata[MetadataValidatorWeight])
221+
require.Equal(uint32(20000), stakeOutOp.Metadata[MetadataDelegationFee])
212222
}
213223

214224
// TODO: Remove Post-Durango
@@ -262,6 +272,9 @@ func TestMapAddDelegatorTx(t *testing.T) {
262272
require.Equal(OpTypeInput, rosettaTransaction.Operations[0].Metadata["type"])
263273
require.Equal(OpTypeOutput, rosettaTransaction.Operations[1].Metadata["type"])
264274
require.Equal(OpTypeStakeOutput, rosettaTransaction.Operations[2].Metadata["type"])
275+
276+
stakeOutOp := rosettaTransaction.Operations[2]
277+
require.Equal(uint64(1000000000), stakeOutOp.Metadata[MetadataValidatorWeight])
265278
}
266279

267280
func TestMapAddPermissionlessDelegatorTx(t *testing.T) {
@@ -314,6 +327,9 @@ func TestMapAddPermissionlessDelegatorTx(t *testing.T) {
314327
require.Equal(OpTypeInput, rosettaTransaction.Operations[0].Metadata["type"])
315328
require.Equal(OpTypeOutput, rosettaTransaction.Operations[1].Metadata["type"])
316329
require.Equal(OpTypeStakeOutput, rosettaTransaction.Operations[2].Metadata["type"])
330+
331+
stakeOutOp := rosettaTransaction.Operations[2]
332+
require.Equal(uint64(1000000000), stakeOutOp.Metadata[MetadataValidatorWeight])
317333
}
318334

319335
func TestMapImportTx(t *testing.T) {

mapper/pchain/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
MetadataValidatorNodeID = "validator_node_id"
4141
MetadataStakingStartTime = "staking_start_time"
4242
MetadataStakingEndTime = "staking_end_time"
43+
MetadataValidatorWeight = "validator_weight"
44+
MetadataDelegationFee = "delegation_fee"
4345
MetadataMessage = "message"
4446
MetadataSigner = "signer"
4547

service/backend/pchain/construction_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ func TestAddValidatorTxConstruction(t *testing.T) {
594594
"delegation_rewards_owner": []string{ewoqAccountP.Address},
595595
"validator_rewards_owner": []string{ewoqAccountP.Address},
596596
"signer": pop,
597+
"validator_weight": uint64(2_000_000_000_000),
598+
"delegation_fee": shares,
597599
},
598600
},
599601
}
@@ -839,6 +841,7 @@ func TestAddDelegatorTxConstruction(t *testing.T) {
839841
"validator_node_id": nodeID,
840842
"subnet_id": pChainID.String(),
841843
"delegator_rewards_owner": []string{ewoqAccountP.Address},
844+
"validator_weight": uint64(25_000_000_000),
842845
},
843846
},
844847
}

0 commit comments

Comments
 (0)