Skip to content

Commit

Permalink
support GetFinalizedBlock by common ratio validators
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx committed Jan 6, 2025
1 parent 7b777da commit 33a1fcd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions turbo/jsonrpc/bsc_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/hexutil"
"github.com/erigontech/erigon-lib/common/math"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/consensus"
"github.com/erigontech/erigon/consensus/parlia"
Expand Down Expand Up @@ -322,9 +323,15 @@ func (api *BscImpl) getFinalizedNumber(ctx context.Context, verifiedValidatorNum
if err != nil { // impossible
return 0, err
}
valLen := int64(len(curValidators))
if verifiedValidatorNum < 1 || verifiedValidatorNum > valLen {
return 0, fmt.Errorf("%d out of range [1,%d]", verifiedValidatorNum, valLen)
valLen := len(curValidators)
if verifiedValidatorNum == -1 {
verifiedValidatorNum = int64(math.CeilDiv(valLen, 2))
} else if verifiedValidatorNum == -2 {
verifiedValidatorNum = int64(math.CeilDiv(valLen*2, 3))
} else if verifiedValidatorNum == -3 {
verifiedValidatorNum = int64(valLen)
} else if verifiedValidatorNum < 1 || verifiedValidatorNum > int64(valLen) {
return 0, fmt.Errorf("%d neither within the range [1,%d] nor the range [-3,-1]", verifiedValidatorNum, valLen)
}

fastFinalizedHeader, err := api.ethApi.headerByRPCNumber(ctx, rpc.FinalizedBlockNumber, tx)
Expand Down

0 comments on commit 33a1fcd

Please sign in to comment.