Skip to content

Commit 6c16868

Browse files
authored
Merge pull request #5124 from oasisprotocol/kostko/stable/22.2.x/backport-5123
2 parents fbac4f5 + 8120981 commit 6c16868

File tree

8 files changed

+136
-29
lines changed

8 files changed

+136
-29
lines changed

.changelog/5120.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rust: Bump tokio from 1.21.2 to 1.24.1

.changelog/5123.bugfix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go/worker/client: Better handle latest round queries with verification
2+
3+
When a query is requesting to be executed against the latest round and
4+
the runtime reports a consensus verifier error, use an earlier round
5+
instead as the latest round may not yet be verifiable by the light
6+
client as it needs to wait for the validator signatures.

Cargo.lock

Lines changed: 70 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/runtime/host/protocol/errors.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package protocol
2+
3+
import (
4+
"github.com/oasisprotocol/oasis-core/go/common/errors"
5+
)
6+
7+
// ModuleVerifierName is the name of the consensus verifier module inside the runtime.
8+
const ModuleVerifierName = "verifier"
9+
10+
// ErrVerifierVerificationFailed is the error returned when consensus verifier fails to verify the
11+
// passed consensus light block.
12+
var ErrVerifierVerificationFailed = errors.New(ModuleVerifierName, 2, "verifier: light block verification failed")

go/worker/client/committee/node.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
cmnBackoff "github.com/oasisprotocol/oasis-core/go/common/backoff"
1313
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
14+
"github.com/oasisprotocol/oasis-core/go/common/errors"
1415
"github.com/oasisprotocol/oasis-core/go/common/logging"
1516
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
1617
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
@@ -149,22 +150,52 @@ func (n *Node) Query(ctx context.Context, round uint64, method string, args []by
149150
}
150151
maxMessages := dsc.Executor.MaxMessages
151152

152-
annBlk, err := n.commonNode.Runtime.History().GetAnnotatedBlock(ctx, round)
153-
if err != nil {
154-
return nil, fmt.Errorf("client: failed to fetch annotated block from history: %w", err)
155-
}
153+
var resolvedRound uint64
154+
queryFn := func(round uint64) ([]byte, error) {
155+
annBlk, err := n.commonNode.Runtime.History().GetAnnotatedBlock(ctx, round)
156+
if err != nil {
157+
return nil, fmt.Errorf("client: failed to fetch annotated block from history: %w", err)
158+
}
159+
resolvedRound = annBlk.Block.Header.Round
156160

157-
// Get consensus light block for state after executing block at given height.
158-
lb, err := n.commonNode.Consensus.GetLightBlockForState(ctx, annBlk.Height)
159-
if err != nil {
160-
return nil, fmt.Errorf("client: failed to get light block at height %d: %w", annBlk.Height, err)
161-
}
162-
epoch, err := n.commonNode.Consensus.Beacon().GetEpoch(ctx, annBlk.Height)
163-
if err != nil {
164-
return nil, fmt.Errorf("client: failed to get epoch at height %d: %w", annBlk.Height, err)
161+
// Get consensus light block for state after executing block at given height.
162+
lb, err := n.commonNode.Consensus.GetLightBlockForState(ctx, annBlk.Height)
163+
if err != nil {
164+
return nil, fmt.Errorf("client: failed to get light block at height %d: %w", annBlk.Height, err)
165+
}
166+
epoch, err := n.commonNode.Consensus.Beacon().GetEpoch(ctx, annBlk.Height)
167+
if err != nil {
168+
return nil, fmt.Errorf("client: failed to get epoch at height %d: %w", annBlk.Height, err)
169+
}
170+
171+
return hrt.Query(ctx, annBlk.Block, lb, epoch, maxMessages, method, args)
165172
}
166173

167-
return hrt.Query(ctx, annBlk.Block, lb, epoch, maxMessages, method, args)
174+
data, err := queryFn(round)
175+
if errors.Is(err, protocol.ErrVerifierVerificationFailed) {
176+
// The query failed due to the runtime's consensus verifier failing to verify the given
177+
// header. We assume that this is because a finalized header is not yet available for the
178+
// given round.
179+
switch round {
180+
case api.RoundLatest:
181+
// Since we are allowed to decide what we see as the latest round, use an earlier one.
182+
n.logger.Debug("runtime's consensus verifier reports failure, retrying",
183+
"method", method,
184+
"target_round", resolvedRound,
185+
)
186+
187+
data, err = queryFn(resolvedRound - 1)
188+
default:
189+
// A specific round was given so this query is not yet possible.
190+
n.logger.Debug("runtime's consensus verifier reports failure",
191+
"method", method,
192+
"target_round", round,
193+
)
194+
195+
return nil, roothash.ErrNotFound
196+
}
197+
}
198+
return data, err
168199
}
169200

170201
func (n *Node) checkBlock(ctx context.Context, blk *block.Block, pending map[hash.Hash]*pendingTx) error {

keymanager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ sp800-185 = "0.2.0"
2222
thiserror = "1.0"
2323
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
2424
x25519-dalek = "1.1.0"
25-
tokio = { version = "~1.21.1", features = ["rt"] }
25+
tokio = { version = "~1.24.1", features = ["rt"] }
2626
zeroize = "1.4.2"

runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ base64 = "0.13.0"
3232
rustc-hex = "2.0.1"
3333
rand = "0.7.3"
3434
futures = "0.3.17"
35-
tokio = { version = "~1.21.1", features = ["rt", "sync"] }
35+
tokio = { version = "~1.24.1", features = ["rt", "sync"] }
3636
tendermint = "0.25.0"
3737
tendermint-proto = "0.25.0"
3838
tendermint-light-client = { version = "0.25.0", default-features = false }

tests/runtimes/simple-keyvalue/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ thiserror = "1.0"
3131
io-context = "0.2.0"
3232
byteorder = "1.4.3"
3333
x25519-dalek = "1.1.0"
34-
tokio = { version = "~1.21.1", features = ["rt"] }
34+
tokio = { version = "~1.24.1", features = ["rt"] }
3535

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

0 commit comments

Comments
 (0)