Skip to content

Commit

Permalink
[api] readState support to non-rolldpos mode (iotexproject#4247)
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc authored May 7, 2024
1 parent 1110804 commit a4ba831
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,29 +932,29 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei
)
ctx = protocol.WithFeatureCtx(protocol.WithFeatureWithHeightCtx(ctx))

rp := rolldpos.FindProtocol(core.registry)
if rp == nil {
return nil, uint64(0), errors.New("rolldpos is not registered")
}

tipEpochNum := rp.GetEpochNum(tipHeight)
if height != "" {
inputHeight, err := strconv.ParseUint(height, 0, 64)
if err != nil {
return nil, uint64(0), err
}
inputEpochNum := rp.GetEpochNum(inputHeight)
if inputEpochNum < tipEpochNum {
rp := rolldpos.FindProtocol(core.registry)
if rp != nil {
tipEpochNum := rp.GetEpochNum(tipHeight)
inputEpochNum := rp.GetEpochNum(inputHeight)
if inputEpochNum < tipEpochNum {
inputHeight = rp.GetEpochHeight(inputEpochNum)
}
}
if inputHeight < tipHeight {
// old data, wrap to history state reader
d, h, err := p.ReadState(ctx, factory.NewHistoryStateReader(core.sf, rp.GetEpochHeight(inputEpochNum)), methodName, arguments...)
d, h, err := p.ReadState(ctx, factory.NewHistoryStateReader(core.sf, inputHeight), methodName, arguments...)
if err == nil {
key.Height = strconv.FormatUint(h, 10)
core.readCache.Put(key.Hash(), d)
}
return d, h, err
}
}

// TODO: need to distinguish user error and system error
d, h, err := p.ReadState(ctx, core.sf, methodName, arguments...)
if err == nil {
Expand Down

0 comments on commit a4ba831

Please sign in to comment.