-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nonce handling with signer (#3196)
Closes: #1910 This covers most cases by serializing the actual broadcasts to the consensus node and enabling resubmissions in the case that there is a sequence mismatch. This covers most fail cases with the possible exception of proposal nodes receiving the transactions in the reverse order to the initial nodes that the user broadcasted to There are also some interesting side affects that need to be handled when an existing accepted transaction is later kicked out of the mempool via CheckTx but overall I think this is a huge improvement for the UX of users
- Loading branch information
Showing
14 changed files
with
450 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package user_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/celestiaorg/celestia-app/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/pkg/user" | ||
"github.com/celestiaorg/celestia-app/test/util/blobfactory" | ||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
"github.com/celestiaorg/go-square/blob" | ||
"github.com/stretchr/testify/require" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
) | ||
|
||
func TestConcurrentTxSubmission(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
|
||
// Setup network | ||
tmConfig := testnode.DefaultTendermintConfig() | ||
tmConfig.Consensus.TimeoutCommit = 10 * time.Second | ||
ctx, _, _ := testnode.NewNetwork(t, testnode.DefaultConfig().WithTendermintConfig(tmConfig)) | ||
_, err := ctx.WaitForHeight(1) | ||
require.NoError(t, err) | ||
|
||
// Setup signer | ||
signer, err := testnode.NewSingleSignerFromContext(ctx) | ||
require.NoError(t, err) | ||
|
||
// Pregenerate all the blobs | ||
numTxs := 10 | ||
blobs := blobfactory.ManyRandBlobs(tmrand.NewRand(), blobfactory.Repeat(2048, numTxs)...) | ||
|
||
// Prepare transactions | ||
var ( | ||
wg sync.WaitGroup | ||
errCh = make(chan error) | ||
) | ||
|
||
subCtx, cancel := context.WithCancel(ctx.GoContext()) | ||
defer cancel() | ||
time.AfterFunc(time.Minute, cancel) | ||
for i := 0; i < numTxs; i++ { | ||
wg.Add(1) | ||
go func(b *blob.Blob) { | ||
defer wg.Done() | ||
_, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{b}, user.SetGasLimitAndFee(500_000, appconsts.DefaultGlobalMinGasPrice)) | ||
if err != nil && !errors.Is(err, context.Canceled) { | ||
// only catch the first error | ||
select { | ||
case errCh <- err: | ||
cancel() | ||
default: | ||
} | ||
} | ||
}(blobs[i]) | ||
} | ||
wg.Wait() | ||
|
||
select { | ||
case err := <-errCh: | ||
require.NoError(t, err) | ||
default: | ||
} | ||
} | ||
|
||
func TestSignerTwins(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
|
||
// Setup network | ||
tmConfig := testnode.DefaultTendermintConfig() | ||
tmConfig.Consensus.TimeoutCommit = 10 * time.Second | ||
ctx, _, _ := testnode.NewNetwork(t, testnode.DefaultConfig().WithTendermintConfig(tmConfig)) | ||
_, err := ctx.WaitForHeight(1) | ||
require.NoError(t, err) | ||
|
||
signer1, err := testnode.NewSingleSignerFromContext(ctx) | ||
require.NoError(t, err) | ||
signer2, err := testnode.NewSingleSignerFromContext(ctx) | ||
require.NoError(t, err) | ||
|
||
blobs := blobfactory.ManyRandBlobs(tmrand.NewRand(), blobfactory.Repeat(2048, 8)...) | ||
|
||
_, err = signer1.SubmitPayForBlob(ctx.GoContext(), blobs[:1], user.SetGasLimitAndFee(500_000, appconsts.DefaultGlobalMinGasPrice)) | ||
require.NoError(t, err) | ||
|
||
_, err = signer2.SubmitPayForBlob(ctx.GoContext(), blobs[1:3], user.SetGasLimitAndFee(500_000, appconsts.DefaultGlobalMinGasPrice)) | ||
require.NoError(t, err) | ||
|
||
signer1.ForceSetSequence(4) | ||
_, err = signer1.SubmitPayForBlob(ctx.GoContext(), blobs[3:5], user.SetGasLimitAndFee(500_000, appconsts.DefaultGlobalMinGasPrice)) | ||
require.NoError(t, err) | ||
} |
Oops, something went wrong.