Skip to content

Commit 567b4a8

Browse files
committed
x
1 parent bd928e4 commit 567b4a8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

action/protocol/staking/protocol.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager
220220
blkCtx := protocol.MustGetBlockCtx(ctx)
221221
hu := config.NewHeightUpgrade(&bcCtx.Genesis)
222222
fmt.Println("CreatePreStates///////", blkCtx.BlockHeight, p.hu.FairbankBlockHeight(), p.hu.GreenlandBlockHeight())
223-
if p.archiveMode && p.hu.IsPre(config.Greenland, blkCtx.BlockHeight) && blkCtx.BlockHeight > 1 {
223+
if p.archiveMode && blkCtx.BlockHeight <= p.hu.GreenlandBlockHeight() && blkCtx.BlockHeight > 1 {
224224
if err := p.saveStakingAddressHistory(blkCtx.BlockHeight, sm); err != nil {
225225
fmt.Println("saveStakingAddressHistory errrrr", err)
226226
return err
@@ -475,7 +475,7 @@ func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, metho
475475
case iotexapi.ReadStakingDataMethod_CANDIDATE_BY_ADDRESS:
476476
resp, height, err = readStateCandidateByAddress(ctx, csr, r.GetCandidateByAddress())
477477
case iotexapi.ReadStakingDataMethod_TOTAL_STAKING_AMOUNT:
478-
if p.archiveMode && p.hu.IsPre(config.Greenland, inputHeight) {
478+
if p.archiveMode && inputHeight <= p.hu.GreenlandBlockHeight() {
479479
resp, height, err = readStateTotalStakingAmountFromIndexer(sr, r.GetTotalStakingAmount(), inputHeight)
480480
//if err != nil {
481481
// resp, height, err = readStateTotalStakingAmount(ctx, csr, r.GetTotalStakingAmount())

action/protocol/staking/read_state.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func readStateTotalStakingAmountFromIndexer(csr protocol.StateReader, _ *iotexap
151151
fmt.Println("readStateTotalStakingAmountFromHeight", height)
152152
meta := iotextypes.AccountMeta{}
153153
meta.Address = address.StakingBucketPoolAddr
154-
total, err := getTotalStakedAmountFromHeight(csr, height)
154+
total, err := getTotalStakedAmountFromIndexer(csr, height)
155155
if err != nil {
156156
return nil, height, err
157157
}
@@ -232,11 +232,14 @@ func getTotalStakedAmount(ctx context.Context, csr CandidateStateReader) (*big.I
232232
return csr.TotalStakedAmount(), nil
233233
}
234234

235-
func getTotalStakedAmountFromHeight(csr protocol.StateReader, height uint64) (*big.Int, error) {
235+
func getTotalStakedAmountFromIndexer(csr protocol.StateReader, height uint64) (*big.Int, error) {
236236
hei := byteutil.Uint64ToBytesBigEndian(height)
237237
historyKey := append(bucketPoolAddrKey, hei...)
238238
var total totalAmount
239239
_, err := csr.State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(historyKey))
240240
fmt.Println("getTotalStakedAmountFromHeight", height, hex.EncodeToString(historyKey), err)
241-
return total.amount, err
241+
if err != nil {
242+
return nil, err
243+
}
244+
return total.amount, nil
242245
}

0 commit comments

Comments
 (0)