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

[WIP][Persistence][Core][Savepoints/Rollbacks] Implement KISS SavePoints - Serialize WorldState from Persistence - KV Stores POC - (Issue #327) #657

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
1762efb
chore(utility): normalize imports
deblasis Mar 9, 2023
305e96a
chore(utility): setBus (from embedded base_module)
deblasis Mar 9, 2023
cc9f7db
refactor(shared): utility module interface changes
deblasis Mar 9, 2023
c859dbb
chore(shared): utilitycontext marked for deprecation
deblasis Mar 9, 2023
771b95e
refactor(shared): utility unitofwork, catering for #508 as well
deblasis Mar 9, 2023
a1d7aab
feat(shared): utility unitofwork for leader and replica for #508
deblasis Mar 9, 2023
06a5694
refactor(shared): mv ReleaseUtilityContext->ReleaseUtilityUnitOfWork
deblasis Mar 9, 2023
f938274
chore(shared): TODO in consensus (ReleaseUtilityUnitOfWork)
deblasis Mar 9, 2023
2b2469b
refactor(shared): refactored ConsensusDebugModule for uow
deblasis Mar 9, 2023
324ae5e
feat(utility): base utilityUnitOfWork
deblasis Mar 9, 2023
69a8fe1
feat(utility): leader utilityUnitOfWork
deblasis Mar 9, 2023
c151bbf
feat(utility): replicaUtilityUnitOfWork
deblasis Mar 9, 2023
d28d2e7
feat(utility): unitOfWork constructor
deblasis Mar 9, 2023
a8d7792
refactor(consensus): utilityUnitOfWork
deblasis Mar 9, 2023
2b93b37
refactor(consensus): utilityUnitOfWork in pacemaker
deblasis Mar 9, 2023
54ca863
chore(consensus): TODO in tests
deblasis Mar 9, 2023
0d6de1b
refactor(consensus): refactored block application to use uow
deblasis Mar 9, 2023
1092e6b
chore(consensus): removed already handled TODO
deblasis Mar 9, 2023
4692611
chore(consensus): removed already handled TODO
deblasis Mar 9, 2023
676e710
feat(consensus): techdebt (maxmempoolbytes from consensus config)
deblasis Mar 9, 2023
68cb452
feat(consensus): using refactored uow for leader logic
deblasis Mar 9, 2023
46f9181
fix(consensus): consolidated maxTxBytes
deblasis Mar 10, 2023
4f86ceb
refactor(consensus): pacemaker_test uow
deblasis Mar 10, 2023
b589396
refactor(shared): updated type for maxTxBytes
deblasis Mar 10, 2023
097787a
refactor(consensus): tests are ✅
deblasis Mar 10, 2023
5e2dca4
refactor(consensus): simplified create / apply
deblasis Mar 11, 2023
7ab68c5
fix(persistence): techdebt: log statement
deblasis Mar 11, 2023
15365fe
refactor(utility): updated create / apply
deblasis Mar 11, 2023
bdf0a5c
refactor(utility): deprecating utilityContext
deblasis Mar 11, 2023
43294c3
refactor(utility): WIP separation of concerns module/uow
deblasis Mar 11, 2023
eb63737
refactor(utility): ctx -> uow + 🧹
deblasis Mar 11, 2023
75c0f18
refactor(utility): simplified TestUtilityContext_ApplyBlock
deblasis Mar 12, 2023
7228de8
chore(utility): renamed tests
deblasis Mar 12, 2023
ae32b35
chore(consensus): updated utilityContext references
deblasis Mar 12, 2023
781af57
docs(shared): updated utilityContext references
deblasis Mar 12, 2023
809005c
chore(consensus): updated utility context references
deblasis Mar 12, 2023
f3bbea3
chore(shared): updated utility context references
deblasis Mar 12, 2023
9fa0a00
refactor(consensus): restored CreateAndApplyProposalBlock
deblasis Mar 12, 2023
a225d37
refactor(utility): CreateAndApplyProposalBlock in leaderUow
deblasis Mar 12, 2023
1be71bd
chore(utility): context 🧹
deblasis Mar 12, 2023
dcccee8
fix(consensus): fix tests
deblasis Mar 12, 2023
d7ee688
chore(utility): lint
deblasis Mar 12, 2023
62f3622
refactor(persistence): removed NewSavePoint([]byte) from interface
deblasis Mar 14, 2023
a8f1306
refactor(persistence): removed NewSavePoint from PostgresContext
deblasis Mar 14, 2023
48d071a
feat(persistence): savepoints prototype
deblasis Mar 14, 2023
bd528bb
feat(persistence): select * in JSON format for all tables
deblasis Mar 14, 2023
528b0dc
feat(persistence): JSON getters
deblasis Mar 14, 2023
656a815
feat(persistence): JSON getters implementations
deblasis Mar 14, 2023
81f08be
feat(persistence): savepoint WIP
deblasis Mar 16, 2023
b9c5e6e
feat(persistence): savepointFactory WIP
deblasis Mar 16, 2023
eef51b0
feat(persistence): POC test
deblasis Mar 16, 2023
7aa75ac
chore(shared): go mod tidy
deblasis Mar 16, 2023
992e620
Merge remote-tracking branch 'upstream/main' into issue/327-kiss-save…
deblasis Apr 2, 2023
023c426
refactor(persistence): savepoint Release()
deblasis Apr 2, 2023
ac167a7
chore(shared): TODOes
deblasis Apr 2, 2023
52063d9
refactor(persistence): improved savepoint
deblasis Apr 2, 2023
7ce96f9
fix(persistence): handling "no results" in JSON db queries
deblasis Apr 3, 2023
6249db3
fix(consensus): fix merge
deblasis Apr 3, 2023
c3c4100
fix(consensus): fix merge
deblasis Apr 3, 2023
b94016f
fix(consensus): merge fix
deblasis Apr 3, 2023
8be8ce1
Merge remote-tracking branch 'upstream/main' into issue/327-kiss-save…
deblasis Apr 5, 2023
a306244
refactor(shared): rm *JSON methods
deblasis Apr 5, 2023
8f729d1
refactor(persistence): cleanup savepoint
deblasis Apr 5, 2023
be01e06
refactor(persistence): cleanup savepoints_factory
deblasis Apr 5, 2023
7ba392e
refactor(go.mod): tidy
deblasis Apr 6, 2023
ab609e1
refactor(shared): pools addresses + added missing fishermanstakepool
deblasis Apr 6, 2023
6c80701
refactor(persistence): removed getaddress hack
deblasis Apr 6, 2023
d3e0c13
chore(persistence): removed comment about the GetAddress hack
deblasis Apr 6, 2023
22ccb7b
refactor(shared): updating pools addresses to real addresses
deblasis Apr 6, 2023
9a55cb4
fix(persistence): fixed pools test that was considering unspecified
deblasis Apr 6, 2023
96b9ecc
refactor(utility): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
159153b
refactor(runtime): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
0f92138
refactor(persistence): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
9afe94c
fix(persistence): params/keys keying fix (name vs hash)
deblasis Apr 6, 2023
b0a6e2c
refactor(shared): pools addresses + added missing fishermanstakepool
deblasis Apr 6, 2023
def2418
refactor(persistence): removed getaddress hack
deblasis Apr 6, 2023
acca48d
chore(persistence): removed comment about the GetAddress hack
deblasis Apr 6, 2023
7fecda7
refactor(shared): updating pools addresses to real addresses
deblasis Apr 6, 2023
94de517
fix(persistence): fixed pools test that was considering unspecified
deblasis Apr 6, 2023
32658ff
refactor(utility): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
858c20b
refactor(runtime): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
b9c9bca
refactor(persistence): using Address() instead of FriendlyName()
deblasis Apr 6, 2023
bad1392
fix(persistence): params/keys keying fix (name vs hash)
deblasis Apr 6, 2023
908e158
test(persistence): updated DeterministicStateWhenUpdatingAppStake
deblasis Apr 6, 2023
6d4a459
test(persistence): updated tests
deblasis Apr 6, 2023
1b1b68f
refactor(shared): updated to use address instead of name
deblasis Apr 6, 2023
608fecc
refactor(utility): updated to use address
deblasis Apr 6, 2023
04596df
refactor(shared): updated pools
deblasis Apr 6, 2023
e438506
refactor(persistence): updated to use address
deblasis Apr 6, 2023
01f550d
refactor(runtime): updated generator
deblasis Apr 6, 2023
ed1b032
chore(shared): lint
deblasis Apr 6, 2023
30a02eb
docs(build): CHANGELOG
deblasis Apr 6, 2023
9f8115e
docs(persistence): CHANGELOG
deblasis Apr 6, 2023
548498d
docs(runtime): CHANGELOG
deblasis Apr 6, 2023
f51c58d
docs(shared): CHANGELOG
deblasis Apr 6, 2023
132785e
docs(utility): CHANGELOG
deblasis Apr 6, 2023
965859d
Merge branch 'issue/persistence_bits_and_bobs1' into issue/327-kiss-s…
deblasis Apr 6, 2023
7dde3c8
fix(persistence): savepoint fix
deblasis Apr 6, 2023
67508da
feat(persistence): backupable kvstore
deblasis Apr 7, 2023
1ad3a13
feat(persistence): kvstore accessors
deblasis Apr 7, 2023
221f4c0
feat(shared): kvstores accessor
deblasis Apr 7, 2023
b9adaaf
feat(persistence): savepoint factory backup phase
deblasis Apr 7, 2023
a0992bd
feat(persistence): savepoint implementation
deblasis Apr 7, 2023
5703cbe
style(shared): GetKVStores -> GetBackupableKVStores
deblasis Apr 7, 2023
522def1
Merge remote-tracking branch 'upstream/main' into issue/327-kiss-save…
deblasis Apr 7, 2023
8c508e9
chore(persistence): 🧹
deblasis Apr 7, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand Down
5 changes: 0 additions & 5 deletions persistence/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type PostgresContext struct {
stateTrees *stateTrees
}

func (p *PostgresContext) NewSavePoint(bytes []byte) error {
p.logger.Info().Bool("TODO", true).Msg("NewSavePoint not implemented")
return nil
}

// TECHDEBT(#327): Guarantee atomicity betweens `prepareBlock`, `insertBlock` and `storeBlock` for save points & rollbacks.
func (p *PostgresContext) RollbackToSavePoint(bytes []byte) error {
p.logger.Info().Bool("TODO", true).Msg("RollbackToSavePoint not fully implemented")
Expand Down
2 changes: 1 addition & 1 deletion persistence/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (p *PostgresContext) GetParameter(paramName string, height int64) (v any, e
case "[]uint8": // []byte
v, _, err = getParamOrFlag[[]byte](p, types.ParamsTableName, paramName, height)
default:
return nil, fmt.Errorf("unhandled type for param: got %s.", paramType)
return nil, fmt.Errorf("unhandled type for param: got %s", paramType)
}
return v, err
}
Expand Down
2 changes: 1 addition & 1 deletion persistence/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewTxIndexer(databasePath string) (TxIndexer, error) {

func NewMemTxIndexer() (TxIndexer, error) {
return &txIndexer{
db: kvstore.NewMemKVStore(),
db: kvstore.NewMemKVStore("txIndexer"),
}, nil
}

Expand Down
55 changes: 51 additions & 4 deletions persistence/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ package kvstore

import (
"errors"
"fmt"
"io"
"log"
"strings"

"github.com/celestiaorg/smt"
badger "github.com/dgraph-io/badger/v3"
)

type KVStore interface {
smt.MapStore // Get, Set, Delete
BackupableKVStore

// Lifecycle methods
Stop() error
Expand All @@ -24,6 +28,11 @@ type KVStore interface {
ClearAll() error
}

type BackupableKVStore interface {
GetName() string
Backup(w io.Writer, since uint64) (uint64, error)
}

const (
BadgerKeyNotFoundError = "Key not found"
)
Expand All @@ -39,23 +48,36 @@ var (
)

type badgerKVStore struct {
db *badger.DB
db *badger.DB
name string
}

func NewKVStore(path string) (KVStore, error) {
db, err := badger.Open(badgerOptions(path))
if err != nil {
return nil, err
}
return &badgerKVStore{db: db}, nil

name, err := extractNameFromPath(path)
if err != nil {
return nil, err
}

return &badgerKVStore{
db: db,
name: name,
}, nil
}

func NewMemKVStore() KVStore {
func NewMemKVStore(name string) KVStore {
db, err := badger.Open(badgerOptions("").WithInMemory(true))
if err != nil {
log.Fatal(err)
}
return &badgerKVStore{db: db}
return &badgerKVStore{
db: db,
name: name,
}
}

func (store *badgerKVStore) Set(key, value []byte) error {
Expand Down Expand Up @@ -148,6 +170,15 @@ func (store *badgerKVStore) Stop() error {
return store.db.Close()
}

// Backup writes a backup of the database to the given writer.
func (store *badgerKVStore) Backup(w io.Writer, since uint64) (uint64, error) {
return store.db.Backup(w, since)
}

func (store *badgerKVStore) GetName() string {
return store.name
}

// PrefixEndBytes returns the end byteslice for a noninclusive range
// that would include all byte slices for which the input is the prefix
func prefixEndBytes(prefix []byte) []byte {
Expand All @@ -171,3 +202,19 @@ func badgerOptions(path string) badger.Options {
opts.Logger = nil // disable badger's logger since it's very noisy
return opts
}

func extractNameFromPath(path string) (string, error) {
if path == "" {
return "", fmt.Errorf("path is empty")
}

parts := strings.Split(path, "/")
nodesPart := parts[len(parts)-1]
name := strings.TrimSuffix(nodesPart, "_nodes")

if name == "" {
return "", fmt.Errorf("invalid path format, name not found in %s", path)
}

return name, nil
}
10 changes: 10 additions & 0 deletions persistence/kvstore_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package persistence

import (
"github.com/pokt-network/pocket/persistence/kvstore"
)

// GetBackupableKVStores returns the node and value kv stores allowing the ability to backup them
func (p *PostgresContext) GetBackupableKVStores() (nodeStores, valueStores map[int]kvstore.BackupableKVStore) {
return p.stateTrees.GetBackupableKVStores()
}
2 changes: 1 addition & 1 deletion persistence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (m *persistenceModule) NewWriteContext() modules.PersistenceRWContext {

func initializeBlockStore(blockStorePath string) (kvstore.KVStore, error) {
if blockStorePath == "" {
return kvstore.NewMemKVStore(), nil
return kvstore.NewMemKVStore("blockStore"), nil
}
return kvstore.NewKVStore(blockStorePath)
}
Expand Down
Loading