fix: do not allow unordered txs to have sequence values set (#24581)

Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
This commit is contained in:
Tyler
2025-04-28 20:55:05 +00:00
committed by GitHub
co-authored by Alex | Interchain Labs Aaron Craelius
parent a158c24b38
commit f9f3bfb066
21 changed files with 255 additions and 46 deletions
+4 -1
View File
@@ -515,6 +515,9 @@ func (f Factory) getSimSignatureData(pk cryptotypes.PubKey) signing.SignatureDat
// A new Factory with the updated fields will be returned.
// Note: When in offline mode, the Prepare does nothing and returns the original factory.
func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
if f.sequence > 0 && f.unordered {
return f, errors.New("unordered transactions must not have sequence values set")
}
if clientCtx.Offline {
return f, nil
}
@@ -537,7 +540,7 @@ func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
fc = fc.WithAccountNumber(num)
}
if initSeq == 0 {
if initSeq == 0 && !f.unordered {
fc = fc.WithSequence(seq)
}
}
+11
View File
@@ -41,6 +41,17 @@ func TestFactoryPrepare(t *testing.T) {
require.NotEqual(t, output, factory)
require.Equal(t, output.AccountNumber(), uint64(10))
require.Equal(t, output.Sequence(), uint64(1))
// sequence and unordered set should break the tx.
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 15}).WithUnordered(true).WithSequence(15)
_, err = factory.Prepare(clientCtx.WithFrom("foo"))
require.ErrorContains(t, err, "unordered transactions must not have sequence values set")
// unordered set should ignore the retrieved sequence value.
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 15}).WithUnordered(true)
output, err = factory.Prepare(clientCtx.WithFrom("foo"))
require.NoError(t, err)
require.Zero(t, output.Sequence())
}
func TestFactory_getSimPKType(t *testing.T) {