feat: upstream changes from server modular (#20584)
This commit is contained in:
parent
514830e56a
commit
439f2f9d5b
@ -113,6 +113,19 @@ func (c *CommitStore) GetLatestVersion() (uint64, error) {
|
||||
return version, nil
|
||||
}
|
||||
|
||||
// IsEmpty returns true if the CommitStore is empty.
|
||||
func (c *CommitStore) IsEmpty() (bool, error) {
|
||||
value, err := c.db.Get([]byte(latestVersionKey))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if value == nil {
|
||||
return true, nil
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CommitStore) LoadVersion(targetVersion uint64) error {
|
||||
// Rollback the metadata to the target version.
|
||||
latestVersion, err := c.GetLatestVersion()
|
||||
@ -167,16 +180,19 @@ func (c *CommitStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error) {
|
||||
}
|
||||
|
||||
func (c *CommitStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) error {
|
||||
// do nothing if commit info is nil, as will be the case for an empty, initializing store
|
||||
if cInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
batch := c.db.NewBatch()
|
||||
if cInfo != nil {
|
||||
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
|
||||
value, err := cInfo.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := batch.Set(cInfoKey, value); err != nil {
|
||||
return err
|
||||
}
|
||||
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
|
||||
value, err := cInfo.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := batch.Set(cInfoKey, value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@ -201,8 +217,11 @@ func (c *CommitStore) Commit(version uint64) (*proof.CommitInfo, error) {
|
||||
// If a commit event execution is interrupted, a new iavl store's version
|
||||
// will be larger than the RMS's metadata, when the block is replayed, we
|
||||
// should avoid committing that iavl store again.
|
||||
var commitID proof.CommitID
|
||||
if tree.GetLatestVersion() >= version {
|
||||
var (
|
||||
commitID proof.CommitID
|
||||
latestVersion = tree.GetLatestVersion()
|
||||
)
|
||||
if latestVersion != 0 && latestVersion >= version {
|
||||
commitID.Version = version
|
||||
commitID.Hash = tree.Hash()
|
||||
} else {
|
||||
|
||||
@ -57,6 +57,9 @@ type Committer interface {
|
||||
// GetCommitInfo returns the CommitInfo for the given version.
|
||||
GetCommitInfo(version uint64) (*proof.CommitInfo, error)
|
||||
|
||||
// IsEmpty returns true if the database is empty.
|
||||
IsEmpty() (bool, error)
|
||||
|
||||
// Close releases associated resources. It should NOT be idempotent. It must
|
||||
// only be called once and any call after may panic.
|
||||
io.Closer
|
||||
|
||||
@ -388,8 +388,13 @@ func (s *Store) writeSC(cs *corestore.Changeset) error {
|
||||
return fmt.Errorf("failed to write batch to SC store: %w", err)
|
||||
}
|
||||
|
||||
isEmpty, err := s.stateCommitment.IsEmpty()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check if SC store is empty: %w", err)
|
||||
}
|
||||
|
||||
var previousHeight, version uint64
|
||||
if s.lastCommitInfo.GetVersion() == 0 && s.initialVersion > 1 {
|
||||
if isEmpty {
|
||||
// This case means that no commit has been made in the store, we
|
||||
// start from initialVersion.
|
||||
version = s.initialVersion
|
||||
|
||||
@ -5,12 +5,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
consensusv1 "cosmossdk.io/x/consensus/types"
|
||||
"cosmossdk.io/x/upgrade/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// PreBlocker will check if there is a scheduled plan and if it is ready to be executed.
|
||||
@ -31,7 +29,6 @@ func (k Keeper) PreBlocker(ctx context.Context) error {
|
||||
}
|
||||
found := err == nil
|
||||
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO remove with consensus messages
|
||||
if !k.DowngradeVerified() {
|
||||
k.SetDowngradeVerified(true)
|
||||
// This check will make sure that we are using a valid binary.
|
||||
@ -97,8 +94,7 @@ func (k Keeper) PreBlocker(ctx context.Context) error {
|
||||
|
||||
// We have an upgrade handler for this upgrade name, so apply the upgrade
|
||||
k.Logger.Info(fmt.Sprintf("applying upgrade \"%s\" at %s", plan.Name, plan.DueAt()))
|
||||
sdkCtx = sdkCtx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter())
|
||||
if err := k.ApplyUpgrade(sdkCtx, plan); err != nil {
|
||||
if err := k.ApplyUpgrade(ctx, plan); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user