Skip to content
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions op-chain-ops/cmd/celo-migrate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Gene
}

// Apply the changes to the state DB.
applyAllocsToState(db, genesis, cfg)
err = applyAllocsToState(db, genesis, cfg)
if err != nil {
return nil, fmt.Errorf("cannot apply allocations to state: %w", err)
}

// Initialize the distribution schedule contract
// This uses the original config which won't enable recent hardforks (and things like the PUSH0 opcode)
Expand Down Expand Up @@ -242,7 +245,7 @@ func applyStateMigrationChanges(config *genesis.DeployConfig, genesis *core.Gene
// If an account already exists, it adds the balance of the new account to the existing balance.
// If the code of an existing account is different from the code in the genesis block, it logs a warning.
// This changes the state root, so `Commit` needs to be called after this function.
func applyAllocsToState(db *state.StateDB, genesis *core.Genesis, config *params.ChainConfig) {
func applyAllocsToState(db *state.StateDB, genesis *core.Genesis, config *params.ChainConfig) error {
log.Info("Starting to migrate OP contracts into state DB")

accountCounter := 0
Expand All @@ -264,9 +267,11 @@ func applyAllocsToState(db *state.StateDB, genesis *core.Genesis, config *params
log.Info("Account already exists with different code and is whitelisted, overwriting...", "address", k)
Comment thread
palango marked this conversation as resolved.
Outdated
} else {
log.Warn("Account already exists with different code and is not whitelisted, overwriting...", "address", k, "oldCode", db.GetCode(k), "newCode", v.Code)
return fmt.Errorf("account already exists with different code and is not whitelisted: %s", k.Hex())
Comment thread
palango marked this conversation as resolved.
Outdated
}
} else {
log.Warn("Account already exists with different code and no whitelist exists", "address", k, "oldCode", db.GetCode(k), "newCode", v.Code)
return fmt.Errorf("account already exists with different code and no whitelist exists: %s", k.Hex())
}

overwriteCounter++
Comment thread
palango marked this conversation as resolved.
Outdated
Expand All @@ -284,6 +289,7 @@ func applyAllocsToState(db *state.StateDB, genesis *core.Genesis, config *params
log.Info("Moved account", "address", k)
}
log.Info("Migrated OP contracts into state DB", "copiedAccounts", accountCounter, "overwrittenAccounts", overwriteCounter)
return nil
}

// setupDistributionSchedule sets up the distribution schedule contract with the correct balance
Expand Down