Skip to content

Commit

Permalink
disable prefill estimated but also add a test for prefill estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
udpatil committed Mar 11, 2024
1 parent 1dae97e commit 7c661bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tasks/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ func (s *scheduler) ProcessAll(ctx sdk.Context, reqs []*sdk.DeliverTxEntry) ([]t
// initialize mutli-version stores if they haven't been initialized yet
s.tryInitMultiVersionStore(ctx)
// prefill estimates
s.PrefillEstimates(reqs)
// This "optimization" path is being disabled because we don't have a strong reason to have it given that it
// s.PrefillEstimates(reqs)
tasks, tasksMap := toTasks(reqs)
s.allTasks = tasks
s.allTasksMap = tasksMap
Expand Down Expand Up @@ -511,8 +512,9 @@ func (s *scheduler) executeTask(task *deliverTxTask) {

// If abort has occurred, return, else set the response and status
if abortOccurred {
task.SetStatus(statusAborted)
task.SetStatus(statusWaiting)
task.Abort = abort
task.Dependencies = append(task.Dependencies, abort.DependentTxIdx)
return
}

Expand Down
55 changes: 55 additions & 0 deletions tasks/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/cachemulti"
"github.com/cosmos/cosmos-sdk/store/dbadapter"
"github.com/cosmos/cosmos-sdk/store/multiversion"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/utils/tracing"
)
Expand All @@ -42,6 +43,25 @@ func requestList(n int) []*sdk.DeliverTxEntry {
return tasks
}

func requestListWithEstimatedWritesets(n int) []*sdk.DeliverTxEntry {
tasks := make([]*sdk.DeliverTxEntry, n)
for i := 0; i < n; i++ {
tasks[i] = &sdk.DeliverTxEntry{
Request: types.RequestDeliverTx{
Tx: []byte(fmt.Sprintf("%d", i)),
},
AbsoluteIndex: i,
EstimatedWritesets: sdk.MappedWritesets{
testStoreKey: multiversion.WriteSet{
string(itemKey): []byte("foo"),
},
},
}

}
return tasks
}

func initTestCtx(injectStores bool) sdk.Context {
ctx := sdk.Context{}.WithContext(context.Background())
keys := make(map[string]sdk.StoreKey)
Expand Down Expand Up @@ -210,6 +230,41 @@ func TestProcessAll(t *testing.T) {
},
expectedErr: nil,
},
{
name: "Test every tx accesses same key with estimated writesets",
workers: 50,
runs: 1,
addStores: true,
requests: requestListWithEstimatedWritesets(1000),
deliverTxFunc: func(ctx sdk.Context, req types.RequestDeliverTx, tx sdk.Tx, checksum [32]byte) (res types.ResponseDeliverTx) {
// all txs read and write to the same key to maximize conflicts
kv := ctx.MultiStore().GetKVStore(testStoreKey)
val := string(kv.Get(itemKey))

// write to the store with this tx's index
kv.Set(itemKey, req.Tx)

// return what was read from the store (final attempt should be index-1)
return types.ResponseDeliverTx{
Info: val,
}
},
assertions: func(t *testing.T, ctx sdk.Context, res []types.ResponseDeliverTx) {
for idx, response := range res {
if idx == 0 {
require.Equal(t, "", response.Info)
} else {
// the info is what was read from the kv store by the tx
// each tx writes its own index, so the info should be the index of the previous tx
require.Equal(t, fmt.Sprintf("%d", idx-1), response.Info)
}
}
// confirm last write made it to the parent store
latest := ctx.MultiStore().GetKVStore(testStoreKey).Get(itemKey)
require.Equal(t, []byte(fmt.Sprintf("%d", len(res)-1)), latest)
},
expectedErr: nil,
},
{
name: "Test some tx accesses same key",
workers: 50,
Expand Down

0 comments on commit 7c661bb

Please sign in to comment.