fix staking read state height issue
@@ -110,14 +110,14 @@ func readStateBucketCount(ctx context.Context, csr CandidateStateReader,
if err != nil {
return nil, 0, err
}
- active, err := getActiveBucketsCount(ctx, csr)
+ active, h, err := getActiveBucketsCount(ctx, csr)
if err != nil {
- return nil, 0, err
+ return nil, h, err
}
return &iotextypes.BucketsCount{
Total: total,
Active: active,
- }, csr.Height(), nil
+ }, h, nil
}
func readStateCandidates(ctx context.Context, csr CandidateStateReader,
@@ -155,12 +155,12 @@ func readStateTotalStakingAmount(ctx context.Context, csr CandidateStateReader,
_ *iotexapi.ReadStakingDataRequest_TotalStakingAmount) (*iotextypes.AccountMeta, uint64, error) {
meta := iotextypes.AccountMeta{}
meta.Address = address.StakingBucketPoolAddr
- total, err := getTotalStakedAmount(ctx, csr)
+ total, h, err := getTotalStakedAmount(ctx, csr)
if err != nil {
- return nil, csr.Height(), err
+ return nil, h, err
}
meta.Balance = total.String()
- return &meta, csr.Height(), nil
+ return &meta, h, nil
}
func toIoTeXTypesVoteBucketList(buckets []*VoteBucket) (*iotextypes.VoteBucketList, error) {
@@ -219,35 +219,35 @@ func getPageOfCandidates(candidates CandidateList, offset, limit int) CandidateL
return res
}
-func getTotalStakedAmount(ctx context.Context, csr CandidateStateReader) (*big.Int, error) {
+func getTotalStakedAmount(ctx context.Context, csr CandidateStateReader) (*big.Int, uint64, error) {
chainCtx := protocol.MustGetBlockchainCtx(ctx)
hu := config.NewHeightUpgrade(&chainCtx.Genesis)
if hu.IsPost(config.Greenland, csr.Height()) {
// after Greenland, read state from db
var total totalAmount
- _, err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
+ h, err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
if err != nil {
- return nil, err
+ return nil, h, err
}
- return total.amount, nil
+ return total.amount, h, nil
}
// otherwise read from bucket pool
- return csr.TotalStakedAmount(), nil
+ return csr.TotalStakedAmount(), csr.Height(), nil
}
-func getActiveBucketsCount(ctx context.Context, csr CandidateStateReader) (uint64, error) {
+func getActiveBucketsCount(ctx context.Context, csr CandidateStateReader) (uint64, uint64, error) {
chainCtx := protocol.MustGetBlockchainCtx(ctx)
hu := config.NewHeightUpgrade(&chainCtx.Genesis)
if hu.IsPost(config.Greenland, csr.Height()) {
// after Greenland, read state from db
var total totalAmount
- _, err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
+ h, err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
if err != nil {
- return 0, err
+ return 0, h, err
}
- return total.count, nil
+ return total.count, h, nil
}
// otherwise read from bucket pool
- return csr.ActiveBucketsCount(), nil
+ return csr.ActiveBucketsCount(), csr.Height(), nil
}
