Skip to content

Commit

Permalink
fix(txpool): check deadlock situation
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Nov 10, 2024
1 parent ec22af1 commit 8ec52dd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func setupWithSeed(t *testing.T, seed int64) *testData {

fmt.Printf("=== test %s, seed: %d\n", t.Name(), seed)

ts := testsuite.NewTestSuiteForSeed(seed)
ts := testsuite.NewTestSuiteFromSeed(seed)

_, valKeys := ts.GenerateTestCommittee(4)
txPool := txpool.MockingTxPool()
Expand Down
2 changes: 1 addition & 1 deletion execution/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type TransactionCommittedError struct {
}

func (e TransactionCommittedError) Error() string {
return fmt.Sprintf("the transaction committed before: %s",
return fmt.Sprintf("the transaction submitted before: %s",

Check warning on line 19 in execution/errors.go

View check run for this annotation

Codecov / codecov/patch

execution/errors.go#L19

Added line #L19 was not covered by tests
e.ID.String())
}

Expand Down
6 changes: 5 additions & 1 deletion txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ func (p *txPool) Size() int {
p.lk.RLock()
defer p.lk.RUnlock()

return p.size()
}

func (p *txPool) size() int {
size := 0
for _, pool := range p.pools {
size += pool.list.Size()
Expand Down Expand Up @@ -345,7 +349,7 @@ func (p *txPool) AllPendingTxs() []*tx.Tx {
p.lk.RLock()
defer p.lk.RUnlock()

txs := make([]*tx.Tx, 0, p.Size())
txs := make([]*tx.Tx, 0, p.size())

var next *linkedlist.Element[linkedmap.Pair[tx.ID, *tx.Tx]]
for _, pool := range p.pools {
Expand Down
3 changes: 1 addition & 2 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ func TestCalculatingConsumption(t *testing.T) {
// Handle the block in the transaction pool
td.pool.HandleCommittedBlock(blk)

// Uncomment me to track consumption map.
// fmt.Println(td.pool.consumptionMap)
t.Logf("consumption Map: %v\n", td.pool.consumptionMap)
}

require.Equal(t, expected, td.pool.consumptionMap)
Expand Down
4 changes: 2 additions & 2 deletions util/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func GenerateSeed() int64 {
return time.Now().UTC().UnixNano()
}

// NewTestSuiteForSeed creates a new TestSuite with the given seed.
func NewTestSuiteForSeed(seed int64) *TestSuite {
// NewTestSuiteFromSeed creates a new TestSuite with the given seed.
func NewTestSuiteFromSeed(seed int64) *TestSuite {
return &TestSuite{
Seed: seed,
//nolint:gosec // to reproduce the failed tests
Expand Down
2 changes: 1 addition & 1 deletion www/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func setup(t *testing.T, conf *Config) *testData {
conf = testConfig()
}

ts := testsuite.NewTestSuiteForSeed(1717506021599855072)
ts := testsuite.NewTestSuite(t)

// for saving test wallets in temp directory
err := os.Chdir(util.TempDirPath())
Expand Down

0 comments on commit 8ec52dd

Please sign in to comment.