From 33a1fcde54ac2d89125ef3388918b73e0820b713 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Mon, 6 Jan 2025 16:02:30 +0800 Subject: [PATCH] support GetFinalizedBlock by common ratio validators --- turbo/jsonrpc/bsc_api.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/turbo/jsonrpc/bsc_api.go b/turbo/jsonrpc/bsc_api.go index 43f7dbf7aab..f3448ee7577 100644 --- a/turbo/jsonrpc/bsc_api.go +++ b/turbo/jsonrpc/bsc_api.go @@ -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" @@ -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)