-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R4R: Judge if trust-node predefined before create certifier add verification for getBlock, queryTx and getValidators #2210
R4R: Judge if trust-node predefined before create certifier add verification for getBlock, queryTx and getValidators #2210
Conversation
…tion in getting blocks, transactions and validator sets
Codecov Report
@@ Coverage Diff @@
## develop #2210 +/- ##
==========================================
- Coverage 64.23% 63.63% -0.6%
==========================================
Files 140 140
Lines 8575 8542 -33
==========================================
- Hits 5508 5436 -72
- Misses 2690 2738 +48
+ Partials 377 368 -9 |
I noticed some todos: getBlock, queryTx and getValidators. The authors want the gaia-lite could verify the proof from response by default. So here I implement the verification functionality and set distrust-node option to true.
The reason is that:
Do you think this is accptable? If not, could you give me some suggestions about how to improve this? |
@HaoyangLiu, I like the approach here, but before going too in depth into a review, I think the nomenclature of I think we should keep Alternatively, to keep things simple. We could have lmk your thoughts @cwgoes |
@alexanderbez |
@alexanderbez
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HaoyangLiu I like this approach better. I left some minor feedback. Otherwise, I tested this and it seems to work. Thanks!
client/context/context.go
Outdated
@@ -69,32 +70,40 @@ func NewCLIContext() CLIContext { | |||
} | |||
|
|||
func createCertifier() tmlite.Certifier { | |||
flagPredefined := viper.IsSet(client.FlagTrustNode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trustNodeDefined
?
client/tx/search.go
Outdated
|
||
// TODO: change this to false once proofs built in | ||
cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses") | ||
cmd.Flags().Bool(client.FlagTrustNode, false, "Don't verify proofs for query responses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we're inconsistent with this flag's description. Can we update all occurrences to something like: Trust connected full node (don't verify proofs for responses)
?
client/tx/query.go
Outdated
// TODO: change this to false when we can | ||
cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses") | ||
cmd.Flags().Bool(client.FlagTrustNode, false, "Don't verify proofs for query responses") | ||
cmd.Flags().String(client.FlagChainID, "", "The chain ID to connect to") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chain ID of Tendermint node
*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested ACK -- thanks!
client/context/query.go
Outdated
@@ -309,7 +309,7 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro | |||
return res, errors.Errorf("query failed: (%d) %s", resp.Code, resp.Log) | |||
} | |||
|
|||
// Data from trusted node or subspace query doesn't need verification | |||
// data from trusted node or subspace query doesn't need verification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize and add trailing period please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry. Could you clarify trailing period please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HaoyangLiu I think he is stating that it should be reverted back to a sentence with a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my pleasure 👍
@@ -177,7 +177,7 @@ func TestBlock(t *testing.T) { | |||
|
|||
// -- | |||
|
|||
res, body = Request(t, port, "GET", "/blocks/1", nil) | |||
res, body = Request(t, port, "GET", "/blocks/2", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a comment about the reason above. When gaia-lite is launched, it will fetch the latest height as its trust basement. Then it can only verify blocks or transactions in later height.
Here gaia-lite is launched after a new block is created, please refer to the code. The wait is necessary. If the height of gaia node is zero, gaia-lite will be aborted for fetching block failure. So here gaia-lite will be start later and it will get block 2 as its trust basement. As a result, it can't verify block 1. As I clear here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we should update gaia lite so that you can easily start it with a separate root-of-trust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #2323
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments, mostly DRY, we can save other changes for later PRs.
client/rpc/block.go
Outdated
@@ -41,6 +44,26 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) { | |||
return nil, err | |||
} | |||
|
|||
trustNode := viper.GetBool(client.FlagTrustNode) | |||
if !trustNode { | |||
check, err := tmliteProxy.GetCertifiedCommit(*height, node, cliCtx.Certifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine this with similar instances below (DRY)
@@ -62,7 +61,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { | |||
c.Flags().Bool(FlagAsync, false, "broadcast transactions asynchronously") | |||
c.Flags().Bool(FlagJson, false, "return output in json format") | |||
c.Flags().Bool(FlagPrintResponse, true, "return tx response (only works with async = false)") | |||
c.Flags().Bool(FlagTrustNode, true, "Don't verify proofs for query responses") | |||
c.Flags().Bool(FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #2322
client/rpc/validators.go
Outdated
trustNode := viper.GetBool(client.FlagTrustNode) | ||
|
||
if !trustNode { | ||
check, err := tmliteProxy.GetCertifiedCommit(*height, node, cliCtx.Certifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY
client/rpc/validators.go
Outdated
@@ -70,6 +75,21 @@ func getValidators(cliCtx context.CLIContext, height *int64) ([]byte, error) { | |||
return nil, err | |||
} | |||
|
|||
trustNode := viper.GetBool(client.FlagTrustNode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fetched from the CLIContext
instead
client/tx/search.go
Outdated
@@ -93,7 +94,21 @@ func searchTxs(cliCtx context.CLIContext, cdc *wire.Codec, tags []string) ([]Inf | |||
if err != nil { | |||
return nil, err | |||
} | |||
if prove { | |||
for _, tx := range res.Txs { | |||
check, err := tmliteProxy.GetCertifiedCommit(tx.Height, node, cliCtx.Certifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY with above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be cached so the loop is OK I think
client/tx/query.go
Outdated
@@ -72,6 +73,20 @@ func queryTx(cdc *wire.Codec, cliCtx context.CLIContext, hashHexStr string, trus | |||
return nil, err | |||
} | |||
|
|||
if !trustNode { | |||
check, err := tmliteProxy.GetCertifiedCommit(info.Height, node, cliCtx.Certifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY with above/below
@@ -177,7 +177,7 @@ func TestBlock(t *testing.T) { | |||
|
|||
// -- | |||
|
|||
res, body = Request(t, port, "GET", "/blocks/1", nil) | |||
res, body = Request(t, port, "GET", "/blocks/2", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #2323
// trustNode defaults to true | ||
if err != nil { | ||
trustNode = true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove this because if rest-server is stared with trust-node option, then we can't verify tx proof even if the request requires proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ready, one more suggested change.
client/tx/query.go
Outdated
func formatTxResult(cdc *wire.Codec, res *ctypes.ResultTx) (Info, error) { | ||
// TODO: verify the proof if requested | ||
func formatTxResult(cdc *wire.Codec, cliCtx context.CLIContext, res *ctypes.ResultTx) (Info, error) { | ||
if !cliCtx.TrustNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is fine but I think it's confusing to put it in a function called formatTxResult
- at first I thought you deleted the proof verification because I expected formatTxResult
to only do formatting! Can we separate this into a different function - maybe validateTxResult
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the verification logic here because I noticed the TODO.
How about I create a new function named validateTxResult
and call it in formatTxResult
, like this:
func formatTxResult(cdc *wire.Codec, cliCtx context.CLIContext, res *ctypes.ResultTx) (Info, error) {
if !cliCtx.TrustNode {
if err := validateTxResult(cliCtx , res); err !=nil {
return ni, err
}
}
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for misunderstanding. I have changed the code move the tx verification out of tx format.
// trustNode defaults to true | ||
if err != nil { | ||
trustNode = true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍
Also merge develop to fix the file conflicts. |
The test_sim_modulues failure seems have no connection with my changes. |
Correct 👍 |
New solution for the issue in #2209
Besides, add verification in getting blocks, transactions and validator sets.
@alexanderbez @cwgoes