Skip to content

Commit

Permalink
Merge pull request #5124 from oasisprotocol/kostko/stable/22.2.x/back…
Browse files Browse the repository at this point in the history
…port-5123
  • Loading branch information
kostko authored Jan 11, 2023
2 parents fbac4f5 + 8120981 commit 6c16868
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 29 deletions.
1 change: 1 addition & 0 deletions .changelog/5120.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rust: Bump tokio from 1.21.2 to 1.24.1
6 changes: 6 additions & 0 deletions .changelog/5123.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go/worker/client: Better handle latest round queries with verification

When a query is requesting to be executed against the latest round and
the runtime reports a consensus verifier error, use an earlier round
instead as the latest round may not yet be verifiable by the light
client as it needs to wait for the validator signatures.
83 changes: 70 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions go/runtime/host/protocol/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package protocol

import (
"github.com/oasisprotocol/oasis-core/go/common/errors"
)

// ModuleVerifierName is the name of the consensus verifier module inside the runtime.
const ModuleVerifierName = "verifier"

// ErrVerifierVerificationFailed is the error returned when consensus verifier fails to verify the
// passed consensus light block.
var ErrVerifierVerificationFailed = errors.New(ModuleVerifierName, 2, "verifier: light block verification failed")
57 changes: 44 additions & 13 deletions go/worker/client/committee/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

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/errors"
"github.com/oasisprotocol/oasis-core/go/common/logging"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
Expand Down Expand Up @@ -149,22 +150,52 @@ func (n *Node) Query(ctx context.Context, round uint64, method string, args []by
}
maxMessages := dsc.Executor.MaxMessages

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)
}
var resolvedRound uint64
queryFn := func(round uint64) ([]byte, error) {
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.
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)
}
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)
// Get consensus light block for state after executing block at given height.
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)
}
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)
}

return hrt.Query(ctx, annBlk.Block, lb, epoch, maxMessages, method, args)
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:
// 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
}

func (n *Node) checkBlock(ctx context.Context, blk *block.Block, pending map[hash.Hash]*pendingTx) error {
Expand Down
2 changes: 1 addition & 1 deletion keymanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ sp800-185 = "0.2.0"
thiserror = "1.0"
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
x25519-dalek = "1.1.0"
tokio = { version = "~1.21.1", features = ["rt"] }
tokio = { version = "~1.24.1", features = ["rt"] }
zeroize = "1.4.2"
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ base64 = "0.13.0"
rustc-hex = "2.0.1"
rand = "0.7.3"
futures = "0.3.17"
tokio = { version = "~1.21.1", features = ["rt", "sync"] }
tokio = { version = "~1.24.1", features = ["rt", "sync"] }
tendermint = "0.25.0"
tendermint-proto = "0.25.0"
tendermint-light-client = { version = "0.25.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion tests/runtimes/simple-keyvalue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ thiserror = "1.0"
io-context = "0.2.0"
byteorder = "1.4.3"
x25519-dalek = "1.1.0"
tokio = { version = "~1.21.1", features = ["rt"] }
tokio = { version = "~1.24.1", features = ["rt"] }

[build-dependencies]
oasis-core-tools = { path = "../../../tools" }

0 comments on commit 6c16868

Please sign in to comment.