Skip to content

Commit

Permalink
Merge pull request #5305 from oasisprotocol/peternose/feature/same-bl…
Browse files Browse the repository at this point in the history
…ock-validation-cleanup

go/worker/client/committee/node: Cleanup method Query
  • Loading branch information
peternose authored Dec 6, 2023
2 parents cea60c8 + 70276ac commit c9974b4
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 139 deletions.
Empty file added .changelog/5305.trivial.md
Empty file.
7 changes: 0 additions & 7 deletions go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,6 @@ type ClientBackend interface {
// client verification.
GetLightBlock(ctx context.Context, height int64) (*LightBlock, error)

// GetLightBlockForState returns a light block for the state as of executing the consensus layer
// block at the specified height. Note that the height of the returned block may differ
// depending on consensus layer implementation details.
//
// In case light block for the given height is not yet available, it returns ErrVersionNotFound.
GetLightBlockForState(ctx context.Context, height int64) (*LightBlock, error)

// State returns a MKVS read syncer that can be used to read consensus state from a remote node
// and verify it against the trusted local root.
State() syncer.ReadSyncer
Expand Down
37 changes: 0 additions & 37 deletions go/consensus/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ var (
methodGetBlock = serviceName.NewMethod("GetBlock", int64(0))
// methodGetLightBlock is the GetLightBlock method.
methodGetLightBlock = serviceName.NewMethod("GetLightBlock", int64(0))
// methodGetLightBlockForState is the GetLightBlockForState method.
methodGetLightBlockForState = serviceName.NewMethod("GetLightBlockForState", int64(0))
// methodGetTransactions is the GetTransactions method.
methodGetTransactions = serviceName.NewMethod("GetTransactions", int64(0))
// methodGetTransactionsWithResults is the GetTransactionsWithResults method.
Expand Down Expand Up @@ -107,10 +105,6 @@ var (
MethodName: methodGetLightBlock.ShortName(),
Handler: handlerGetLightBlock,
},
{
MethodName: methodGetLightBlockForState.ShortName(),
Handler: handlerGetLightBlockForState,
},
{
MethodName: methodGetTransactions.ShortName(),
Handler: handlerGetTransactions,
Expand Down Expand Up @@ -358,29 +352,6 @@ func handlerGetLightBlock(
return interceptor(ctx, height, info, handler)
}

func handlerGetLightBlockForState(
srv interface{},
ctx context.Context,
dec func(interface{}) error,
interceptor grpc.UnaryServerInterceptor,
) (interface{}, error) {
var height int64
if err := dec(&height); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ClientBackend).GetLightBlockForState(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodGetLightBlockForState.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ClientBackend).GetLightBlockForState(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}

func handlerGetTransactions(
srv interface{},
ctx context.Context,
Expand Down Expand Up @@ -753,14 +724,6 @@ func (c *consensusClient) GetLightBlock(ctx context.Context, height int64) (*Lig
return &rsp, nil
}

func (c *consensusClient) GetLightBlockForState(ctx context.Context, height int64) (*LightBlock, error) {
var rsp LightBlock
if err := c.conn.Invoke(ctx, methodGetLightBlockForState.FullName(), height, &rsp); err != nil {
return nil, err
}
return &rsp, nil
}

func (c *consensusClient) GetTransactions(ctx context.Context, height int64) ([][]byte, error) {
var rsp [][]byte
if err := c.conn.Invoke(ctx, methodGetTransactions.FullName(), height, &rsp); err != nil {
Expand Down
28 changes: 1 addition & 27 deletions go/consensus/cometbft/full/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
cmtcoretypes "github.com/cometbft/cometbft/rpc/core/types"
cmtrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
"github.com/cometbft/cometbft/state"
cmtstate "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/store"
cmttypes "github.com/cometbft/cometbft/types"

Expand Down Expand Up @@ -559,15 +558,6 @@ func (n *commonNode) GetBlock(ctx context.Context, height int64) (*consensusAPI.

// Implements consensusAPI.Backend.
func (n *commonNode) GetLightBlock(ctx context.Context, height int64) (*consensusAPI.LightBlock, error) {
return n.getLightBlock(ctx, height, false)
}

// Implements consensusAPI.Backend.
func (n *commonNode) GetLightBlockForState(ctx context.Context, height int64) (*consensusAPI.LightBlock, error) {
return n.getLightBlock(ctx, height+1, true)
}

func (n *commonNode) getLightBlock(ctx context.Context, height int64, allowPending bool) (*consensusAPI.LightBlock, error) {
if err := n.ensureStarted(ctx); err != nil {
return nil, err
}
Expand All @@ -589,24 +579,8 @@ func (n *commonNode) getLightBlock(ctx context.Context, height int64, allowPendi
if err == nil && commit != nil && commit.Header != nil {
lb.SignedHeader = &commit.SignedHeader
tmHeight = commit.Header.Height
} else if allowPending {
// The specified height seems to be for the "next" block that has not yet been finalized. We
// construct a "pending" block instead (this block cannot be verified by a light client as
// it doesn't have any commits).
var state cmtstate.State
state, err = n.stateStore.Load()
if err != nil {
return nil, fmt.Errorf("cometbft: failed to fetch latest blockchain state: %w", err)
}

commit := cmttypes.NewCommit(height, 0, cmttypes.BlockID{}, nil)
var proposerAddr [20]byte
blk := state.MakeBlock(height, nil, commit, nil, proposerAddr[:])
lb.SignedHeader = &cmttypes.SignedHeader{
Header: &blk.Header,
Commit: commit,
}
}

protoLb, err := lb.ToProto()
if err != nil {
return nil, fmt.Errorf("cometbft: failed to convert light block: %w", err)
Expand Down
64 changes: 0 additions & 64 deletions go/worker/client/committee/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ package committee

import (
"context"
"errors"
"fmt"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/eapache/channels"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
cmnBackoff "github.com/oasisprotocol/oasis-core/go/common/backoff"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
runtime "github.com/oasisprotocol/oasis-core/go/runtime/api"
"github.com/oasisprotocol/oasis-core/go/runtime/client/api"
Expand Down Expand Up @@ -140,66 +136,6 @@ func (n *Node) Query(ctx context.Context, round uint64, method string, args []by
return nil, api.ErrNoHostedRuntime
}
maxMessages := dsc.Executor.MaxMessages
latestRound := n.commonNode.CurrentBlock.Header.Round

rtInfo, err := hrt.GetInfo(ctx)
if err != nil {
return nil, fmt.Errorf("client: failed to fetch runtime info: %w", err)
}

// TODO: Remove once same block consensus validation is deployed.
if !rtInfo.Features.SameBlockConsensusValidation {
var resolvedRound uint64
queryFn := func(round uint64) ([]byte, error) {
var annBlk *roothash.AnnotatedBlock
annBlk, err = n.commonNode.Runtime.History().GetAnnotatedBlock(ctx, round)
if err != nil {
return nil, fmt.Errorf("client: failed to fetch annotated block from history: %w", err)
}
resolvedRound = annBlk.Block.Header.Round

// Get consensus light block for state after executing block at given height.
var lb *consensus.LightBlock
lb, err = n.commonNode.Consensus.GetLightBlockForState(ctx, annBlk.Height)
if err != nil {
return nil, fmt.Errorf("client: failed to get light block at height %d: %w", annBlk.Height, err)
}
var epoch beacon.EpochTime
epoch, err = n.commonNode.Consensus.Beacon().GetEpoch(ctx, annBlk.Height)
if err != nil {
return nil, fmt.Errorf("client: failed to get epoch at height %d: %w", annBlk.Height, err)
}

return hrt.Query(ctx, annBlk.Block, lb, epoch, maxMessages, method, args)
}

var data []byte
data, err = queryFn(round)
if errors.Is(err, protocol.ErrVerifierVerificationFailed) {
// The query failed due to the runtime's consensus verifier failing to verify the given
// header. We assume that this is because a finalized header is not yet available for the
// given round.
switch round {
case api.RoundLatest, latestRound:
// Since we are allowed to decide what we see as the latest round, use an earlier one.
n.logger.Debug("runtime's consensus verifier reports failure, retrying",
"method", method,
"target_round", resolvedRound,
)

data, err = queryFn(resolvedRound - 1)
default:
// A specific round was given so this query is not yet possible.
n.logger.Debug("runtime's consensus verifier reports failure",
"method", method,
"target_round", round,
)

return nil, roothash.ErrNotFound
}
}
return data, err
}

annBlk, err := n.commonNode.Runtime.History().GetAnnotatedBlock(ctx, round)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ pub struct Features {
/// A feature specifying that the runtime supports rotating key manager's master secret.
#[cbor(optional)]
pub key_manager_master_secret_rotation: bool,
/// A feature specifying that the runtime supports same-block consensus validation.
#[cbor(optional)]
pub same_block_consensus_validation: bool,
}

impl Default for Features {
Expand All @@ -360,7 +357,6 @@ impl Default for Features {
key_manager_quote_policy_updates: true,
key_manager_status_updates: true,
key_manager_master_secret_rotation: false,
same_block_consensus_validation: true,
}
}
}
Expand Down

0 comments on commit c9974b4

Please sign in to comment.