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

Rollback and Snapshot support for remote storage #433

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 5 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/improbable-eng/grpc-web v0.15.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/onflow/cadence v0.42.1
github.com/onflow/flow-archive v1.3.4-0.20230503192214-9e81e82d4dcc
github.com/onflow/flow-archive v0.31.14
github.com/onflow/flow-go v0.32.3
github.com/onflow/flow-go-sdk v0.41.12
github.com/onflow/flow-go/crypto v0.24.9
Expand Down Expand Up @@ -58,10 +58,6 @@ require (
github.com/ethereum/go-ethereum v1.9.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/gammazero/deque v0.1.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down Expand Up @@ -105,10 +101,8 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
Expand All @@ -124,7 +118,6 @@ require (
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 // indirect
github.com/onflow/sdks v0.5.0 // indirect
github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
Expand All @@ -138,8 +131,8 @@ require (
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/cors v1.8.0 // indirect
github.com/schollz/progressbar/v3 v3.13.1 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
Expand Down Expand Up @@ -171,7 +164,6 @@ require (
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand All @@ -193,3 +185,6 @@ require (

//TODO: Remove when both version will be merged
replace github.com/onflow/flow-go v0.32.3 => github.com/Guitarheroua/flow-go v0.0.0-20231024184136-247768e776f7

//TODO: change this when flow-archive PR is merged
replace github.com/onflow/flow-archive => github.com/bluesign/flow-dps v1.4.8-0.20231107143842-75c6d48ac313
35 changes: 3 additions & 32 deletions go.sum

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func (s *EmulatorServer) Stop() {
}

func configureStorage(conf *Config) (storageProvider storage.Store, err error) {

if conf.RedisURL != "" {
storageProvider, err = util.NewRedisStorage(conf.RedisURL)
if err != nil {
Expand Down Expand Up @@ -346,25 +347,17 @@ func configureStorage(conf *Config) (storageProvider storage.Store, err error) {
}

if conf.ChainID == flowgo.Testnet || conf.ChainID == flowgo.Mainnet {
// TODO: any reason redis shouldn't work?
baseProvider, ok := storageProvider.(*sqlite.Store)
if !ok {
return nil, fmt.Errorf("only sqlite is supported with forked networks")
}

provider, err := remote.New(baseProvider, remote.WithChainID(conf.ChainID))
storageProvider, err = remote.New(
storageProvider,
remote.WithChainID(conf.ChainID),
remote.WithForkHeight(conf.StartBlockHeight),
)

if err != nil {
return nil, err
}

if conf.StartBlockHeight > 0 {
err = provider.SetBlockHeight(conf.StartBlockHeight)
if err != nil {
return nil, err
}
}

storageProvider = provider
}

if conf.Snapshot {
Expand Down
1 change: 1 addition & 0 deletions server/utils/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (m EmulatorAPIServer) Rollback(w http.ResponseWriter, r *http.Request) {
err = m.emulator.RollbackToBlockHeight(height)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}

Expand Down
5 changes: 5 additions & 0 deletions storage/memstore/memstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func New() *Store {

var _ storage.Store = &Store{}

func (s *Store) SetBlockHeight(height uint64) error {
//mem-store does not support SetBlockHeight
return nil
}

func (s *Store) Start() error {
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions storage/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading