Hip30 : localnet account migration fix (#4508)

* flags: set up preimage flags

* hip30: set up preimage import, export, api

* save pre-images by default

* add pre images api

* goimports

* commit rpc preimages file

* preimages: re-generate them using CLI

* add metrics and numbers for pre-images

* automate generation after import

* move from rpc to core

* goimports

* add back core/preimages.go file

* HIP-30: sharding configuration boilerplate

* update comments

* goimports

* HIP-30: minimum validator commission of 7%

Based on #4495, which must be merged before this PR. This PR should be
rebased with dev after #4495 is merged to retain atomicity of changes by
pull request.

* goimports

* HIP-30: Emission split implementation

Note that the allocated split of the emission goes directly to the
recipient (and not via the Reward). This is because rewards are indexed
by validator and not by delegator, and the recipient may/may not have
any delegations which we can reward. Even if one was guaranteed to
exist, it would mess up the math of the validator.

* set up mainnet recipient of emission split

* HIP-30: Emission split addresses for non mainnet

* HIP-30: deactivate shard 2 and 3 validators

* goimports

* update test

* goimports

* migrate balance uring epoch T - 1

highly untested code. also missing is the ability to generate a
pre-migration report for future verification.

* update test

* export prometheus metric when no error importing preimage

* add comment

* test account migration in localnet

* add preimages flags to rootflags

* enable preimages on the whitelist

* add the generate method

* fix cropping log

* fix cropping log

* cropping startpoint when bigger than endpoint

* add support for the rpcblocknumer type

* enable import api

* use earlies block

* debug logs

* debug logs

* debug logs

* debug logs

* fix error catching

* fix error catching

* make end optional for the comand line

* fix cropping logic

* improve error when apply message fails

* add balance on the error

* fix importing

* remove unused imports

* create preimage for genesis block

* fix consensus with No Migration Possible

* use correct header for migration

* process all tx in all block for non shard 0

---------

Co-authored-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
Co-authored-by: Diego Nava <diego.nava77@hotmail.com>
Co-authored-by: Diego Nava <8563843+diego1q2w@users.noreply.github.com>
pull/4510/head
Soph 1 year ago committed by GitHub
parent 29d46b9a14
commit ed08ff34de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      core/genesis.go
  2. 14
      core/state_processor.go
  3. 4
      internal/configs/sharding/localnet.go
  4. 1
      node/node_newblock.go
  5. 2
      rpc/preimages.go

@ -28,6 +28,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
@ -252,6 +253,12 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
for key, value := range account.Storage {
statedb.SetState(addr, key, value)
}
//statedb.AddPreimage(crypto.Keccak256Hash((addr[:])), addr.Bytes()[:])
rawdb.WritePreimages(
statedb.Database().DiskDB(), map[ethCommon.Hash][]byte{
crypto.Keccak256Hash((addr.Bytes())): addr.Bytes(),
},
)
}
root := statedb.IntermediateRoot(false)
shardStateBytes, err := shard.EncodeWrapper(g.ShardState, false)

@ -145,7 +145,7 @@ func (p *StateProcessor) Process(
// ran out of accounts
processTxsAndStxs = false
}
if !errors.Is(err, ErrNoMigrationRequired) {
if !errors.Is(err, ErrNoMigrationRequired) && !errors.Is(err, ErrNoMigrationPossible) {
return nil, nil, nil, nil, 0, nil, statedb, err
}
} else {
@ -576,13 +576,9 @@ func MayBalanceMigration(
if isDevnet || isLocalnet {
if config.IsOneEpochBeforeHIP30(header.Epoch()) {
if myShard := chain.ShardID(); myShard != shard.BeaconChainShardID {
parent := chain.GetBlockByHash(
parentRoot := chain.GetBlockByHash(
header.ParentHash(),
)
if parent == nil {
return nil, errors.Wrap(ErrNoMigrationPossible, "parent is nil")
}
parentRoot := parent.Root()
).Root() // for examining MPT at this root, should exist
// for examining MPT at this root, should exist
cx, err := generateOneMigrationMessage(
db, parentRoot,
@ -641,13 +637,11 @@ func generateOneMigrationMessage(
key := accountIterator.LeafKey()
preimage := rawdb.ReadPreimage(db, common.BytesToHash(key))
if len(preimage) == 0 {
e := errors.New(
return nil, errors.New(
fmt.Sprintf(
"cannot find preimage for %x", key,
),
)
fmt.Println(e)
continue
}
address := common.BytesToAddress(preimage)
// skip blank address

@ -31,8 +31,8 @@ const (
localnetV1Epoch = 1
localnetEpochBlock1 = 5
localnetBlocksPerEpoch = 8
localnetBlocksPerEpochV2 = 8
localnetBlocksPerEpoch = 64
localnetBlocksPerEpochV2 = 64
localnetVdfDifficulty = 5000 // This takes about 10s to finish the vdf
)

@ -157,6 +157,7 @@ func (node *Node) ProposeNewBlock(commitSigs chan []byte) (*types.Block, error)
}
}
// Execute all the time except for last block of epoch for shard 0
if !shard.Schedule.IsLastBlock(header.Number().Uint64()) || node.Consensus.ShardID != 0 {
// Prepare normal and staking transactions retrieved from transaction pool
utils.AnalysisStart("proposeNewBlockChooseFromTxnPool")

@ -23,7 +23,7 @@ func NewPreimagesAPI(hmy *hmy.Harmony, version string) rpc.API {
}
}
func (s *PreimagesService) Export(_ context.Context, path string) error {
func (s *PreimagesService) Export(ctx context.Context, path string) error {
// these are by default not blocking
return core.ExportPreimages(s.hmy.BlockChain, path)
}

Loading…
Cancel
Save