Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Apr 23, 2024
2 parents d67c143 + 728d4c7 commit c436492
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
push:
branches:
- v0.37.x
- release/v0.37.x-classic

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
push:
branches:
- v0.37.x
- release/v0.37.x-classic

jobs:
e2e-test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
pull_request:
push:
branches:
- v0.37.x
- release/v0.37.x-classic

jobs:
golangci:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Markdown Linter
on:
push:
branches:
- v0.37.x
- release/v0.37.x-classic
paths:
- "**.md"
- "**.yml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- 'proto/**'
push:
branches:
- v0.37.x
- release/v0.37.x-classic
paths:
- 'proto/**'

Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/release-version.yml

This file was deleted.

76 changes: 0 additions & 76 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths:
- "**.go"
branches:
- v0.37.x
- release/v0.37.x-classic

jobs:
tests:
Expand Down
1 change: 1 addition & 0 deletions mempool/v0/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ func (mem *CListMempool) ReapMaxTxs(max int) types.Txs {
memTx := e.Value.(*mempoolTx)
txs = append(txs, memTx.tx)
}

return txs
}

Expand Down
135 changes: 135 additions & 0 deletions mempool/v0/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,141 @@ func checkTxs(t *testing.T, mp mempool.Mempool, count int, peerID uint16) types.
return txs
}

func TestOraclePriorityResp(t *testing.T) {
app := oracle.NewApplication(true)
cc := proxy.NewLocalClientCreator(app)

mp, cleanup := newMempoolWithApp(cc)
defer cleanup()

appConnCon, _ := cc.NewABCIClient()
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
err := appConnCon.Start()
require.Nil(t, err)

cacheMap := make(map[string]struct{})
deliverTxsRange := func(start, end int) {
// Deliver some txs.
for i := start; i < end; i++ {

// This will succeed
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
err := mp.CheckTx(txBytes, nil, mempool.TxInfo{})
_, cached := cacheMap[string(txBytes)]
if cached {
require.NotNil(t, err, "expected error for cached tx")
} else {
require.Nil(t, err, "expected no err for uncached tx")
}
cacheMap[string(txBytes)] = struct{}{}

// Duplicates are cached and should return error
err = mp.CheckTx(txBytes, nil, mempool.TxInfo{})
require.NotNil(t, err, "Expected error after CheckTx on duplicated tx")
}
}

reapCheck := func(exp int) {
txs := mp.ReapMaxBytesMaxGas(-1, -1)
require.Equal(t, len(txs), exp, fmt.Sprintf("Expected to reap %v txs but got %v", exp, len(txs)))

oddFound := false
for _, tx := range txs {
if binary.BigEndian.Uint64(tx)%2 != 0 {
oddFound = true
} else if oddFound {
require.Fail(t, "oracle txs must be comes first")
}
}
}

oracleTxsCheck := func(exp int) {
require.Equal(t, mp.oracleTxs.Len(), exp, fmt.Sprintf("Expected to reap %v txs but got %v", exp, mp.oracleTxs.Len()))
}

updateRange := func(start, end int) {
txs := make([]types.Tx, 0)
for i := start; i < end; i++ {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
txs = append(txs, txBytes)
}
if err := mp.Update(0, txs, abciResponses(len(txs), abci.CodeTypeOK), nil, nil); err != nil {
t.Error(err)
}
}

commitRange := func(start, end int) {
// Deliver some txs.
for i := start; i < end; i++ {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
res, err := appConnCon.DeliverTxSync(abci.RequestDeliverTx{Tx: txBytes})
if err != nil {
t.Errorf("client error committing tx: %v", err)
}
if res.IsErr() {
t.Errorf("error committing tx. Code:%v result:%X log:%v",
res.Code, res.Data, res.Log)
}
}
res, err := appConnCon.CommitSync()
if err != nil {
t.Errorf("client error committing: %v", err)
}
if len(res.Data) != 8 {
t.Errorf("error committing. Hash:%X", res.Data)
}
}

//----------------------------------------

// Deliver some txs.
deliverTxsRange(0, 100)

// Reap the txs.
reapCheck(100)

// Oracle txs must be 50
oracleTxsCheck(50)

// Reap again. We should get the same amount
reapCheck(100)

// Deliver 0 to 999, we should reap 900 new txs
// because 100 were already counted.
deliverTxsRange(0, 1000)

// Reap the txs.
reapCheck(1000)

// Oracle txs must be 500
oracleTxsCheck(500)

// Reap again. We should get the same amount
reapCheck(1000)

// Commit from the conensus AppConn
commitRange(0, 500)
updateRange(0, 500)

// We should have 500 left.
reapCheck(500)

// Oracle txs must be 250
oracleTxsCheck(250)

// Deliver 100 invalid txs and 100 valid txs
deliverTxsRange(900, 1100)

// We should have 600 now.
reapCheck(600)

// Oracle txs must be 250
oracleTxsCheck(300)
}

func TestReapMaxBytesMaxGas(t *testing.T) {
app := kvstore.NewApplication()
cc := proxy.NewLocalClientCreator(app)
Expand Down

0 comments on commit c436492

Please sign in to comment.