Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Persistence] Adds atomic Update for TreeStore #861

Merged
merged 34 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d8d8ddf
[chore] submodule pattern updates to TreeStore
dylanlott Jul 11, 2023
1a5777c
updates TreeStore to use Submodule type
dylanlott Jul 12, 2023
f87518a
[fixup] embeds TreeStoreFactory on to TreeStoreModule
dylanlott Jul 12, 2023
671598d
[fixup] TreeStoreOption and TreeStoreModule updates
dylanlott Jul 12, 2023
c988cbc
[fixup] get height provider from bus in tree tests
dylanlott Jul 17, 2023
4ae3912
[Temp] s/TreeStore/treeStore (#920)
Olshansk Jul 19, 2023
a601002
[fixup] formatting long mock definitions
dylanlott Jul 20, 2023
795ce87
[chore] submodule pattern updates to TreeStore
dylanlott Jul 11, 2023
4df81fe
[feature] adds atomic rollbacks to TreeStore
dylanlott Jul 11, 2023
f77f764
linter updates
dylanlott Jul 11, 2023
674d539
[fixup] pass testing.T to the newTestApp function
dylanlott Jul 12, 2023
5ee3f42
treestore tests use testing.T instead of err returns
dylanlott Jul 17, 2023
713017b
[fixup] privatizes treeStoreDir field
dylanlott Jul 18, 2023
7f947f9
[fixup] fix path for treestore mock generations
dylanlott Jul 19, 2023
d70a067
[fixup] use method to fetch context instead
dylanlott Jul 19, 2023
d107ed0
[fixup] adds comments and updates tests
dylanlott Jul 19, 2023
626ea5d
[fixup] adds optimize comment to save function
dylanlott Jul 19, 2023
b3ab6b0
[fixup] cleanup
dylanlott Jul 20, 2023
fc04ab0
[docs] updates package level comment
dylanlott Jul 20, 2023
2af89dd
[fixup] adds comments and updates logger use
dylanlott Jul 21, 2023
8ed31bf
dylanlott Jul 21, 2023
09097ef
[rename] s/NewSavePoint/SetSavePoint/g
dylanlott Jul 21, 2023
07b64da
[fixup] update test names and use constants in tests
dylanlott Jul 21, 2023
1ecfde6
[fixup] adds better comment to treeStore#Rollback
dylanlott Jul 21, 2023
a687768
[tests] adds a test for failing rollback
dylanlott Jul 24, 2023
800b2cb
[fixup] check rollback error value to satisfy linter
dylanlott Jul 24, 2023
0b22519
[test] adds a test for block proposal revert
dylanlott Jul 25, 2023
ba85105
[fixup] fix linter error
dylanlott Jul 25, 2023
7a7d95c
[fixup] updates rollback test to use Errors#Is
dylanlott Jul 26, 2023
0f87f0b
[fixup] prevent import cycle error errors in treestore
dylanlott Jul 27, 2023
cb4497d
[fixup] reduce export footprint of worldState
dylanlott Jul 27, 2023
6ce32dc
[docs] update rollback comment
dylanlott Jul 27, 2023
7bad92e
[fixup] s/trees_hash1/treesHash1/
dylanlott Jul 29, 2023
4d218dc
[fixup] adds a happy path test for CreateProposalBlock
dylanlott Jul 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[fixup] adds comments and updates tests
  • Loading branch information
dylanlott committed Jul 27, 2023
commit d107ed0ed484118985aca356440286512cd37fcf
1 change: 1 addition & 0 deletions persistence/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var protocolActorSchemas = []types.ProtocolActorSchema{
types.ValidatorActor,
}

// TECHDEBT(#595): Properly handle context threading and passing for the entire persistence module
func (pg *PostgresContext) getCtxAndTx() (context.Context, pgx.Tx) {
return context.TODO(), pg.tx
}
Expand Down
18 changes: 7 additions & 11 deletions persistence/trees/atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,26 @@ func TestTreeStore_AtomicUpdates(t *testing.T) {
logger: &zerolog.Logger{},
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
treeStoreDir: ":memory:",
}
err := ts.setupTrees()
require.NoError(t, err)
require.NotEmpty(t, ts)
require.NoError(t, ts.setupTrees())
require.NotEmpty(t, ts.merkleTrees[TransactionsTreeName])

hash0 := ts.getStateHash()
require.NotEmpty(t, hash0)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved

err = ts.Savepoint()
require.NoError(t, err)
require.NoError(t, ts.Savepoint())

for _, treeName := range stateTreeNames {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
err := ts.merkleTrees[treeName].tree.Update([]byte("foo"), []byte("bar"))
require.NoError(t, err)
}
err = ts.Commit()
require.NoError(t, err)

require.NoError(t, ts.Commit())

hash1 := ts.getStateHash()
require.NotEmpty(t, hash1)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
require.NotEqual(t, hash0, hash1)

err = ts.Savepoint()
require.NoError(t, err)
require.NoError(t, ts.Savepoint())
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
require.NotEmpty(t, ts.Prev.MerkleTrees)
require.NotEmpty(t, ts.Prev.RootTree)
require.Equal(t, hash1, hex.EncodeToString(ts.Prev.RootTree.tree.Root()))
Expand All @@ -62,8 +59,7 @@ func TestTreeStore_AtomicUpdates(t *testing.T) {
}

for _, treeName := range stateTreeNames {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
err := ts.merkleTrees[treeName].tree.Update([]byte("fiz"), []byte("buz"))
require.NoError(t, err)
require.NoError(t, ts.merkleTrees[treeName].tree.Update([]byte("fiz"), []byte("buz")))
}

ts.Rollback()
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
33 changes: 21 additions & 12 deletions persistence/trees/trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/pokt-network/pocket/shared/modules"
"github.com/pokt-network/pocket/shared/utils"
"github.com/pokt-network/smt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -47,22 +46,28 @@ var (
func TestTreeStore_Update(t *testing.T) {
pool, resource, dbUrl := test_artifacts.SetupPostgresDocker()
t.Cleanup(func() {
if err := pool.Purge(resource); err != nil {
log.Fatalf("could not purge resource: %s", err)
}
require.NoError(t, pool.Purge(resource))
})

t.Run("should update actor tree and commit", func(t *testing.T) {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
pmod := newTestPersistenceModule(t, dbUrl)
context := NewTestPostgresContext(t, 0, pmod)

actor, err := createAndInsertDefaultTestApp(t, context)
assert.NoError(t, err)
require.NoError(t, context.NewSavePoint())

t.Logf("actor inserted %+v", actor)
hash, err := context.ComputeStateHash()
assert.NoError(t, err)
assert.NotEmpty(t, hash)
hash1, err := context.ComputeStateHash()
require.NoError(t, err)
require.NotEmpty(t, hash1)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved

_, err = createAndInsertDefaultTestApp(t, context)
require.NoError(t, err)

require.NoError(t, context.NewSavePoint())

hash2, err := context.ComputeStateHash()
require.NoError(t, err)
require.NotEmpty(t, hash2)
require.NotEqual(t, hash1, hash2)
})
}

Expand Down Expand Up @@ -96,14 +101,15 @@ func newTestPersistenceModule(t *testing.T, databaseUrl string) modules.Persiste
runtimeMgr := runtime.NewManager(cfg, genesisState)

bus, err := runtime.CreateBus(runtimeMgr)
assert.NoError(t, err)
require.NoError(t, err)

persistenceMod, err := persistence.Create(bus)
assert.NoError(t, err)
require.NoError(t, err)

return persistenceMod.(modules.PersistenceModule)
}
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
func createAndInsertDefaultTestApp(t *testing.T, db *persistence.PostgresContext) (*coreTypes.Actor, error) {
t.Helper()
app := newTestApp(t)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved

addrBz, err := hex.DecodeString(app.Address)
Expand Down Expand Up @@ -145,6 +151,7 @@ func newTestApp(t *testing.T) *coreTypes.Actor {
}

func NewTestPostgresContext(t testing.TB, height int64, testPersistenceMod modules.PersistenceModule) *persistence.PostgresContext {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()
rwCtx, err := testPersistenceMod.NewRWContext(height)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatalf("Error creating new context: %v\n", err)
Expand All @@ -164,6 +171,8 @@ func NewTestPostgresContext(t testing.TB, height int64, testPersistenceMod modul
return postgresCtx
}

// TECHDEBT: Extract these test functions out into a central test location
// REFERENCE: https://www.notion.so/pocketnetwork/Testutils-9cba9010e18447248e9daa8a3b87e3f2#f1d7f404918541bc86ccde07980e3f09
func NewTestPersistenceModule(t *testing.T, databaseUrl string) modules.PersistenceModule {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
teardownDeterministicKeygen := keygen.GetInstance().SetSeed(42)
defer teardownDeterministicKeygen()
Expand Down