-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from bloxapp/stage
Stage to Main (v0.1.6 preparation)
- Loading branch information
Showing
12 changed files
with
256 additions
and
34 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ibft | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// decidedGenesisMigrator | ||
type decidedGenesisMigrator struct { | ||
logger *zap.Logger | ||
} | ||
|
||
// Migrate take care of decided messages migration | ||
func (m *decidedGenesisMigrator) Migrate(r Reader) error { | ||
dr, ok := r.(*decidedReader) | ||
if !ok { | ||
return nil | ||
} | ||
n, err := m.migrate(dr) | ||
if err != nil { | ||
return errors.Wrap(err, "could not migrate decided 0") | ||
} | ||
m.logger.Debug("managed to migrate decided 0", | ||
zap.String("identifier", string(dr.identifier)), zap.Int("items", n)) | ||
return nil | ||
} | ||
|
||
// migrate performing migration for decided messages | ||
func (m *decidedGenesisMigrator) migrate(dr *decidedReader) (int, error) { | ||
if migrateDecided0, err := m.check(dr); err != nil { | ||
return 0, err | ||
} else if migrateDecided0 { | ||
return dr.newHistorySync().StartRange(uint64(0), uint64(1)) | ||
} | ||
return 0, nil | ||
} | ||
|
||
// check determines if the given reader should migrate | ||
func (m *decidedGenesisMigrator) check(dr *decidedReader) (bool, error) { | ||
_, found, err := dr.storage.GetDecided(dr.identifier, uint64(0)) | ||
if err != nil { | ||
return false, err | ||
} | ||
if found { | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ibft | ||
|
||
import ( | ||
"github.com/bloxapp/ssv/utils/logex" | ||
"go.uber.org/zap" | ||
"sync" | ||
) | ||
|
||
// Migrator is an interface for migrating messages | ||
type Migrator interface { | ||
Migrate(r Reader) error | ||
} | ||
|
||
type mainMigrator struct { | ||
migrators []Migrator | ||
} | ||
|
||
var migrator mainMigrator | ||
|
||
var migratorOnce sync.Once | ||
|
||
// GetMainMigrator returns the instance of migrator | ||
func GetMainMigrator() Migrator { | ||
migratorOnce.Do(func() { | ||
logger := logex.GetLogger(zap.String("who", "migrateManager")) | ||
migrators := []Migrator{&decidedGenesisMigrator{logger}} | ||
migrator = mainMigrator{ | ||
migrators: migrators, | ||
} | ||
}) | ||
return &migrator | ||
} | ||
|
||
// Migrate applies the existing migrators on the given reader | ||
func (mm *mainMigrator) Migrate(r Reader) error { | ||
for _, migrator := range mm.migrators { | ||
if err := migrator.Migrate(r); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.