@@ -8,7 +8,6 @@ package staking
8
8
9
9
import (
10
10
"context"
11
- "encoding/hex"
12
11
"fmt"
13
12
"math/big"
14
13
"time"
@@ -29,7 +28,6 @@ import (
29
28
"github.com/iotexproject/iotex-core/blockchain/genesis"
30
29
"github.com/iotexproject/iotex-core/config"
31
30
"github.com/iotexproject/iotex-core/pkg/log"
32
- "github.com/iotexproject/iotex-core/pkg/util/byteutil"
33
31
"github.com/iotexproject/iotex-core/state"
34
32
)
35
33
@@ -222,13 +220,7 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager
222
220
bcCtx := protocol .MustGetBlockchainCtx (ctx )
223
221
blkCtx := protocol .MustGetBlockCtx (ctx )
224
222
hu := config .NewHeightUpgrade (& bcCtx .Genesis )
225
- fmt .Println ("CreatePreStates///////" , blkCtx .BlockHeight , p .hu .FairbankBlockHeight (), p .hu .GreenlandBlockHeight ())
226
- if p .archiveMode && blkCtx .BlockHeight <= p .hu .GreenlandBlockHeight () && blkCtx .BlockHeight > 1 {
227
- if err := p .saveStakingAddressHistory (blkCtx .BlockHeight , sm ); err != nil {
228
- fmt .Println ("saveStakingAddressHistory errrrr" , err )
229
- return err
230
- }
231
- }
223
+
232
224
if blkCtx .BlockHeight == hu .GreenlandBlockHeight () {
233
225
csr , err := ConstructBaseView (sm )
234
226
if err != nil {
@@ -251,6 +243,13 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager
251
243
if p .candBucketsIndexer == nil {
252
244
return nil
253
245
}
246
+ fmt .Println ("CreatePreStates///////" , blkCtx .BlockHeight , p .hu .FairbankBlockHeight (), p .hu .GreenlandBlockHeight ())
247
+ if p .archiveMode && blkCtx .BlockHeight <= p .hu .GreenlandBlockHeight () && blkCtx .BlockHeight > 1 {
248
+ if err := p .saveStakingAddressHistory (blkCtx .BlockHeight , sm ); err != nil {
249
+ fmt .Println ("saveStakingAddressHistory errrrr" , err )
250
+ return err
251
+ }
252
+ }
254
253
rp := rolldpos .MustGetProtocol (protocol .MustGetRegistry (ctx ))
255
254
currentEpochNum := rp .GetEpochNum (blkCtx .BlockHeight )
256
255
if currentEpochNum == 0 {
@@ -274,14 +273,7 @@ func (p *Protocol) saveStakingAddressHistory(height uint64, sm protocol.StateMan
274
273
if balance .amount .Sign () <= 0 {
275
274
return nil
276
275
}
277
-
278
- hei := byteutil .Uint64ToBytesBigEndian (height - 1 )
279
- //hei := byteutil.Uint64ToBytesBigEndian(height)
280
- historyKey := append (bucketPoolAddrKey , hei ... )
281
- fmt .Println ("saveStakingAddressHistory2" , height , []byte (StakingNameSpaceForStakingAddress ), hex .EncodeToString (historyKey ), balance .amount )
282
-
283
- _ , err = sm .PutState (balance , protocol .NamespaceOption (StakingNameSpaceForStakingAddress ), protocol .KeyOption (historyKey ))
284
- return err
276
+ return p .candBucketsIndexer .PutStakingBalance (height , balance )
285
277
}
286
278
287
279
func (p * Protocol ) handleStakingIndexer (epochStartHeight uint64 , sm protocol.StateManager ) error {
@@ -479,10 +471,7 @@ func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, metho
479
471
resp , height , err = readStateCandidateByAddress (ctx , csr , r .GetCandidateByAddress ())
480
472
case iotexapi .ReadStakingDataMethod_TOTAL_STAKING_AMOUNT :
481
473
if p .archiveMode && inputHeight <= p .hu .GreenlandBlockHeight () {
482
- resp , height , err = readStateTotalStakingAmountFromIndexer (sr , r .GetTotalStakingAmount (), inputHeight )
483
- //if err != nil {
484
- // resp, height, err = readStateTotalStakingAmount(ctx, csr, r.GetTotalStakingAmount())
485
- //}
474
+ resp , height , err = p .candBucketsIndexer .GetStakingBalance (inputHeight )
486
475
} else {
487
476
resp , height , err = readStateTotalStakingAmount (ctx , csr , r .GetTotalStakingAmount ())
488
477
}
0 commit comments