-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: Implement a simulate-only CLI flag/field for REST endpoints #2181
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2181 +/- ##
==========================================
- Coverage 63.58% 63.48% -0.1%
==========================================
Files 137 137
Lines 8419 8444 +25
==========================================
+ Hits 5353 5361 +8
- Misses 2699 2717 +18
+ Partials 367 366 -1 |
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.
@alessio I left some initial feedback. Thanks!
client/flags.go
Outdated
@@ -58,6 +59,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(FlagDryRun, false, "no action; ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it") |
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 think we can remove no action;
as the description gives a good enough...description 👍
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 usually aim to make command line flags docs stupid-proof :)
Removing "no action" is not a big deal though 👍
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.
Oh and btw, I took inspiration from man apt-get
:
-s, --simulate, --just-print, --dry-run, --recon, --no-act No action; perform a simulation of events that would occur based on the current system state but do not actually change the system. [snip]
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.
#defeated
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.
LOL sorry, amended now
client/utils/utils.go
Outdated
@@ -15,57 +15,35 @@ import ( | |||
// DefaultGasAdjustment is applied to gas estimates to avoid tx | |||
// execution failures due to state changes that might | |||
// occur between the tx simulation and the actual run. | |||
const DefaultGasAdjustment = 1.2 | |||
const DefaultGasAdjustment = 1.0 |
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.
Is it useful or maybe even potentially dangerous to have this defined in two places? Seems its already part of the CLIContext
?
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.
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.
It may not just work for staking transactions, where previous txs in the same block would adjust the gas required.
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 see. What would you suggest then?
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.
Well the gas adjustment is part of the CLIContext
. Why not just set it upstream (where the default can be used)? Is that not possible?
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.
A sane default (i.e. != 0) is required for REST endpoints too.
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.
We can really choose any number and revisit during code freeze time.
client/utils/utils.go
Outdated
func EnrichCtxWithGas(txCtx authctx.TxContext, cliCtx context.CLIContext, name, passphrase string, msgs []sdk.Msg) (authctx.TxContext, error) { | ||
txBytes, err := BuildAndSignTxWithZeroGas(txCtx, name, passphrase, msgs) | ||
// SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value. | ||
func SimulateMsgs(txCtx authctx.TxContext, cliCtx context.CLIContext, name string, msgs []sdk.Msg, gas int64) (int64, int64, error) { |
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 think it'll help understanding if the return arguments are named.
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.
Agreed, will amend
x/auth/ante.go
Outdated
@@ -68,6 +68,9 @@ func NewAnteHandler(am AccountMapper, fck FeeCollectionKeeper) sdk.AnteHandler { | |||
sigs := stdTx.GetSignatures() | |||
signerAddrs := stdTx.GetSigners() | |||
msgs := tx.GetMsgs() | |||
if simulate { |
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.
Can you add a comment explaining this?
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.
ACKd
x/auth/ante.go
Outdated
@@ -160,14 +159,14 @@ func processSig( | |||
|
|||
// Check account number. | |||
accnum := acc.GetAccountNumber() | |||
if accnum != sig.AccountNumber { | |||
if !simulate && (accnum != sig.AccountNumber) { |
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.
Im thinking in the following functions, things might be easer to comprehend if there was just a single simulate
or !simulate
condition and group everything in that code block.
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.
ACKd
x/auth/ante.go
Outdated
return nil, sdk.ErrInternal("setting PubKey on signer's account").Result() | ||
} | ||
|
||
// Check sig. |
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.
Redundant comment I think.
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.
ACKd
x/auth/client/context/context.go
Outdated
|
||
// BuildWithPubKey builds a single message to be signed and | ||
// attach the public key associated to the given name. | ||
func (ctx TxContext) BuildWithPubKey(name string, msgs []sdk.Msg) ([]byte, error) { |
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.
We don't plan on signing this do we?
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.
Nope, nonetheless I needed it to build a spec of signature-less transaction
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.
Ohhh, I was referring to the godoc 👍 . It might need to be updated.
I've addressed your comments @alexanderbez, thanks! |
4f10e64
to
60e3383
Compare
client/utils/utils.go
Outdated
@@ -15,57 +15,35 @@ import ( | |||
// DefaultGasAdjustment is applied to gas estimates to avoid tx | |||
// execution failures due to state changes that might | |||
// occur between the tx simulation and the actual run. | |||
const DefaultGasAdjustment = 1.2 | |||
const DefaultGasAdjustment = 1.0 |
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.
It may not just work for staking transactions, where previous txs in the same block would adjust the gas required.
x/auth/ante.go
Outdated
return nil, sdk.ErrInvalidSequence( | ||
fmt.Sprintf("Invalid account number. Got %d, expected %d", sig.AccountNumber, accnum)).Result() | ||
} | ||
|
||
// Check and increment sequence number. | ||
seq := acc.GetSequence() | ||
if seq != sig.Sequence { | ||
if !simulate && (seq != sig.Sequence) { |
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 confused, you should still have the correct sequence number when simulating a tx?
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.
When simulating, sig
would be empty - line 68, sigs := stdTx.GetSignatures()
, sigs
would just be a 0-length slice.
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.
Makes sense, can you add a comment here explaining that?
Approach so far LGTM |
ACKd, and committed+pushed.
…On Wed, Aug 29, 2018 at 6:46 PM, Dev Ojha ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In x/auth/ante.go
<#2181 (comment)>:
> return nil, sdk.ErrInvalidSequence(
fmt.Sprintf("Invalid account number. Got %d, expected %d", sig.AccountNumber, accnum)).Result()
}
// Check and increment sequence number.
seq := acc.GetSequence()
- if seq != sig.Sequence {
+ if !simulate && (seq != sig.Sequence) {
Makes sense, can you add a comment here explaining that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2181 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAN_7EblMba-uCJM32Dn72NvU2YrkjK6ks5uVtNrgaJpZM4WRUym>
.
--
Alessio Treglia | alessio@tendermint.com
0416 0004 A827 6E40 BB98 90FB E8A4 8AE5 311D 765A
|
941687e
to
9c316e2
Compare
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.
Left some more feedback @alessio -- thanks!
client/flags.go
Outdated
@@ -58,6 +59,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(FlagDryRun, false, "no action; ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it") |
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.
#defeated
client/utils/utils.go
Outdated
@@ -15,57 +15,35 @@ import ( | |||
// DefaultGasAdjustment is applied to gas estimates to avoid tx | |||
// execution failures due to state changes that might | |||
// occur between the tx simulation and the actual run. | |||
const DefaultGasAdjustment = 1.2 | |||
const DefaultGasAdjustment = 1.0 |
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.
Well the gas adjustment is part of the CLIContext
. Why not just set it upstream (where the default can be used)? Is that not possible?
x/auth/client/context/context.go
Outdated
|
||
// BuildWithPubKey builds a single message to be signed and | ||
// attach the public key associated to the given name. | ||
func (ctx TxContext) BuildWithPubKey(name string, msgs []sdk.Msg) ([]byte, error) { |
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.
Ohhh, I was referring to the godoc 👍 . It might need to be updated.
e460e3e
to
afe48fc
Compare
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.
One small remark on a comment section, but otherwise utACK 👍
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.
Pretty good, just a few suggestions.
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.
utACK pending merge conflict resolution
Add a simulate only flag '--dry-run' to both CLI tx commands and RESTful endpoints to trigger the simulation of unsigned transactions. * Turning --dry-run on causes the --gas flag to be ignored. The simulation will return the estimate of the gas required to actually run the transaction. * Adjustment is no longer required. It now defaults to 1.0. * In some test cases accounts retrieved from the state do not come with a PubKey. In such cases, a fake secp256k1 key is generated and gas consumption calculated accordingly. Closes: #2110
This is to address @alexanderbez's comments
045d444
to
cd8f0b4
Compare
cd8f0b4
to
d84885c
Compare
@cwgoes ready to go 👍 |
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.
utACK, thanks @alessio
Let's make sure to test this out by hand prior to the 0.25 release.
Add an extra simulate flag support to both CLI tx commands and RESTful endpoints to trigger the simulation of an unsigned transaction. Relevant changes:
--dry-run
causes the--gas
flag to be ignored. The simulation will return the estimate of the gas required to actually run the transaction.1.0
.PubKey
. In such cases, a fakesecp256k1
key is generated and gas consumption calculated accordingly.Closes: #2110
docs/
)PENDING.md
with issue #Files changed
in the github PR explorerFor Admin Use: