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] update test names and use constants in tests
  • Loading branch information
dylanlott committed Jul 27, 2023
commit 07b64da6adb0c67dfd030a2c8e10e8b5716dc9b4
12 changes: 12 additions & 0 deletions persistence/trees/atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
"github.com/stretchr/testify/require"
)

const (
// the root hash of a tree store where each tree is empty but present and initialized
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
h0 = "302f2956c084cc3e0e760cf1b8c2da5de79c45fa542f68a660a5fc494b486972"
// the root hash of a tree store where each tree has has key foo value bar added to it
h1 = "7d5712ea1507915c40e295845fa58773baa405b24b87e9d99761125d826ff915"
)

func TestTreeStore_AtomicUpdatesWithSuccessfulRollback(t *testing.T) {
ctrl := gomock.NewController(t)

Expand All @@ -32,6 +39,7 @@ func TestTreeStore_AtomicUpdatesWithSuccessfulRollback(t *testing.T) {

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

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

Expand All @@ -48,6 +56,7 @@ func TestTreeStore_AtomicUpdatesWithSuccessfulRollback(t *testing.T) {
hash1 := ts.getStateHash()
require.NotEmpty(t, hash1)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
require.NotEqual(t, hash0, hash1)
require.Equal(t, hash1, h1)

// set a new savepoint
require.NoError(t, ts.Savepoint())
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -56,8 +65,10 @@ func TestTreeStore_AtomicUpdatesWithSuccessfulRollback(t *testing.T) {
// assert that savepoint creation doesn't mutate state hash
require.Equal(t, hash1, hex.EncodeToString(ts.PrevState.RootTree.tree.Root()))

// verify that creating a savepoint does not change state hash
hash2 := ts.getStateHash()
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, hash2, hash1)
require.Equal(t, hash2, h1)

// validate that state tree was updated and a previous savepoint is created
for _, treeName := range stateTreeNames {
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -76,4 +87,5 @@ func TestTreeStore_AtomicUpdatesWithSuccessfulRollback(t *testing.T) {
// validate that the state hash is unchanged after new data was inserted but rolled back before commitment
hash3 := ts.getStateHash()
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, hash3, hash2)
require.Equal(t, hash3, h1)
}
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 0 additions & 3 deletions persistence/trees/trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ func (t *treeStore) updateMerkleTrees(pgtx pgx.Tx, txi indexer.TxIndexer, height
}
}

if err := t.Commit(); err != nil {
return "", fmt.Errorf("failed to commit: %w", err)
}
return t.getStateHash(), nil
}

Expand Down
45 changes: 28 additions & 17 deletions persistence/trees/trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ var (
genesisStateNumApplications = 1
)

const (
h1 = "5282ee91a3ec0a6f2b30e4780b369bae78c80ef3ea40587fef6ae263bf41f244"
)

func TestTreeStore_Update(t *testing.T) {
pool, resource, dbUrl := test_artifacts.SetupPostgresDocker()
t.Cleanup(func() {
require.NoError(t, pool.Purge(resource))
})

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

Expand All @@ -52,6 +56,7 @@ func TestTreeStore_Update(t *testing.T) {
hash1, err := context.ComputeStateHash()
require.NoError(t, err)
require.NotEmpty(t, hash1)
dylanlott marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, hash1, h1)

_, err = createAndInsertDefaultTestApp(t, context)
require.NoError(t, err)
Expand All @@ -65,26 +70,12 @@ func TestTreeStore_Update(t *testing.T) {
})
}

func newTestPersistenceModule(t *testing.T, databaseUrl string) modules.PersistenceModule {
func newTestPersistenceModule(t *testing.T, databaseURL string) modules.PersistenceModule {
t.Helper()
teardownDeterministicKeygen := keygen.GetInstance().SetSeed(42)
defer teardownDeterministicKeygen()

cfg := &configs.Config{
Persistence: &configs.PersistenceConfig{
PostgresUrl: databaseUrl,
NodeSchema: testSchema,
BlockStorePath: ":memory:",
TxIndexerPath: ":memory:",
TreesStoreDir: ":memory:",
MaxConnsCount: 5,
MinConnsCount: 1,
MaxConnLifetime: "5m",
MaxConnIdleTime: "1m",
HealthCheckPeriod: "30s",
},
}

cfg := newTestDefaultConfig(t, databaseURL)
genesisState, _ := test_artifacts.NewGenesisState(
genesisStateNumValidators,
genesisStateNumServicers,
Expand All @@ -102,6 +93,26 @@ func newTestPersistenceModule(t *testing.T, databaseUrl string) modules.Persiste

return persistenceMod.(modules.PersistenceModule)
}
dylanlott marked this conversation as resolved.
Show resolved Hide resolved

// fetches a new default node configuration for testing
func newTestDefaultConfig(t *testing.T, databaseURL string) *configs.Config {
t.Helper()
cfg := &configs.Config{
Persistence: &configs.PersistenceConfig{
PostgresUrl: databaseURL,
NodeSchema: testSchema,
BlockStorePath: ":memory:",
TxIndexerPath: ":memory:",
TreesStoreDir: ":memory:",
MaxConnsCount: 5,
MinConnsCount: 1,
MaxConnLifetime: "5m",
MaxConnIdleTime: "1m",
HealthCheckPeriod: "30s",
},
}
return cfg
}
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
Expand Down