Skip to content

Commit

Permalink
Merge branch 'master' into fxamacker/add-util-to-check-storage-health
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker authored Aug 20, 2024
2 parents c23ce78 + 2266069 commit bb5d146
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 809 deletions.
15 changes: 15 additions & 0 deletions cmd/util/ledger/util/registers_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ func NewByAccountRegistersFromPayloadAccountGrouping(
*registers.ByAccount,
error,
) {
accountCount := payloadAccountGrouping.Len()

if accountCount == 0 {
return registers.NewByAccount(), nil
}

// Set nWorker to be the lesser of nWorker and accountCount
// but greater than 0.
nWorker = min(nWorker, accountCount)
nWorker = max(nWorker, 1)

g, ctx := errgroup.WithContext(context.Background())

jobs := make(chan *PayloadAccountGroup, nWorker)
Expand Down Expand Up @@ -81,6 +92,10 @@ func NewByAccountRegistersFromPayloadAccountGrouping(
for accountRegisters := range results {
oldAccountRegisters := registersByAccount.SetAccountRegisters(accountRegisters)
if oldAccountRegisters != nil {
// TODO: check full migration logs to see if this edge case of multiple groups
// for an account still exists. If it still exists, create an issue to fix it.
// Otherwise, we can treat this as error and panic (instead of merging groups).

// Account grouping should never create multiple groups for an account.
// In case it does anyway, merge the groups together,
// by merging the existing registers into the new ones.
Expand Down
5 changes: 3 additions & 2 deletions engine/execution/computation/computer/computer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type blockComputer struct {
maxConcurrency int
}

func SystemChunkContext(vmCtx fvm.Context) fvm.Context {
func SystemChunkContext(vmCtx fvm.Context, metrics module.ExecutionMetrics) fvm.Context {
return fvm.NewContextFromParent(
vmCtx,
fvm.WithContractDeploymentRestricted(false),
Expand All @@ -131,6 +131,7 @@ func SystemChunkContext(vmCtx fvm.Context) fvm.Context {
fvm.WithMemoryAndInteractionLimitsDisabled(),
// only the system transaction is allowed to call the block entropy provider
fvm.WithRandomSourceHistoryCallAllowed(true),
fvm.WithMetricsReporter(metrics),
)
}

Expand Down Expand Up @@ -158,7 +159,7 @@ func NewBlockComputer(
return nil, fmt.Errorf("program cache writes are not allowed in scripts on Execution nodes")
}

systemChunkCtx := SystemChunkContext(vmCtx)
systemChunkCtx := SystemChunkContext(vmCtx, metrics)
vmCtx = fvm.NewContextFromParent(
vmCtx,
fvm.WithMetricsReporter(metrics),
Expand Down
12 changes: 12 additions & 0 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,18 @@ func Test_ExecutingSystemCollection(t *testing.T) {
mock.Anything).
Return(nil)

metrics.On("RuntimeTransactionParsed", mock.Anything)
metrics.On("RuntimeTransactionProgramsCacheMiss")
metrics.On("RuntimeTransactionProgramsCacheHit")
metrics.On("RuntimeTransactionChecked", mock.Anything)
metrics.On("RuntimeTransactionInterpreted", mock.Anything)

metrics.On("EVMBlockExecuted",
mock.Anything,
mock.Anything,
mock.Anything,
)

bservice := requesterunit.MockBlobService(blockstore.NewBlockstore(dssync.MutexWrap(datastore.NewMapDatastore())))
trackerStorage := mocktracker.NewMockStorage()

Expand Down
7 changes: 0 additions & 7 deletions fvm/environment/facade_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/onflow/flow-go/fvm/storage/snapshot"
"github.com/onflow/flow-go/fvm/storage/state"
"github.com/onflow/flow-go/fvm/tracing"
"github.com/onflow/flow-go/model/flow"
)

var _ Environment = &facadeEnvironment{}
Expand Down Expand Up @@ -338,12 +337,6 @@ func (*facadeEnvironment) GetInterpreterSharedState() *interpreter.SharedState {
}

func (env *facadeEnvironment) RecoverProgram(program *ast.Program, location common.Location) (*ast.Program, error) {
// Enabled on all networks but Mainnet,
// until https://github.com/onflow/flips/pull/283 got approved.
if env.chain.ChainID() == flow.Mainnet {
return nil, nil
}

return RecoverProgram(
env,
env.chain.ChainID(),
Expand Down
15 changes: 8 additions & 7 deletions fvm/environment/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ const (
)

// MainnetExecutionEffortWeights are the execution effort weights as they are
// on mainnet from 18.8.2022
// on mainnet from crescendo spork
var MainnetExecutionEffortWeights = meter.ExecutionEffortWeights{
common.ComputationKindStatement: 1569,
common.ComputationKindLoop: 1569,
common.ComputationKindFunctionInvocation: 1569,
ComputationKindGetValue: 808,
ComputationKindCreateAccount: 2837670,
ComputationKindSetValue: 765,
common.ComputationKindStatement: 314,
common.ComputationKindLoop: 314,
common.ComputationKindFunctionInvocation: 314,
ComputationKindGetValue: 162,
ComputationKindCreateAccount: 567534,
ComputationKindSetValue: 153,
ComputationKindEVMGasUsage: 13,
}

type Meter interface {
Expand Down
46 changes: 1 addition & 45 deletions fvm/evm/emulator/state/account.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package state

import (
"math/big"

"github.com/holiman/uint256"
gethCommon "github.com/onflow/go-ethereum/common"
gethTypes "github.com/onflow/go-ethereum/core/types"
Expand Down Expand Up @@ -59,47 +57,5 @@ func DecodeAccount(inp []byte) (*Account, error) {
return nil, nil
}
a := &Account{}
// try decoding
err := rlp.DecodeBytes(inp, a)
if err != nil {
// try legacy decoding (fall back)
a = decodeLegacy(inp)
// if no success return the initial error
if a == nil {
return nil, err
}
}
return a, nil

}

// TODO: remove it when the Preview is shut down
// Legacy account type - used big.Int for balances
type accountV0 struct {
// address
Address gethCommon.Address
// balance of the address
Balance *big.Int
// nonce of the address
Nonce uint64
// hash of the code
// if no code the gethTypes.EmptyCodeHash is stored
CodeHash gethCommon.Hash
// the id of the collection holds storage slots for this account
// this value is nil for EOA accounts
CollectionID []byte
}

func decodeLegacy(encoded []byte) *Account {
a0 := &accountV0{}
if err := rlp.DecodeBytes(encoded, a0); err == nil {
return &Account{
Address: a0.Address,
Balance: uint256.MustFromBig(a0.Balance),
Nonce: a0.Nonce,
CodeHash: a0.CodeHash,
CollectionID: a0.CollectionID,
}
}
return nil
return a, rlp.DecodeBytes(inp, a)
}
68 changes: 6 additions & 62 deletions fvm/evm/handler/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const (
BlockHashListCapacity = 256
BlockStoreLatestBlockKey = "LatestBlock"
BlockStoreLatestBlockProposalKey = "LatestBlockProposal"
BlockStoreBlockHashesKey = "LatestBlockHashes"
)

type BlockStore struct {
Expand Down Expand Up @@ -167,75 +166,20 @@ func (bs *BlockStore) BlockHash(height uint64) (gethCommon.Hash, error) {
}

func (bs *BlockStore) getBlockHashList() (*BlockHashList, error) {
// check legacy block hash list first
return bs.checkLegacyAndMigrate()
// TODO: when preview net is out, we can remove the call to legacy and uncomment below
// BlockStoreBlockHashesKey constant also be removed
//
// bhl, err := NewBlockHashList(bs.backend, bs.rootAddress, BlockHashListCapacity)
// if err != nil {
// return nil, err
// }
// if bhl.IsEmpty() {
// err = bhl.Push(
// types.GenesisBlock(bs.chainID).Height,
// types.GenesisBlockHash(bs.chainID),
// )
// if err != nil {
// return nil, err
// }
// }
// return bhl, nil
}

func (bs *BlockStore) checkLegacyAndMigrate() (*BlockHashList, error) {
data, err := bs.backend.GetValue(bs.rootAddress[:], []byte(BlockStoreBlockHashesKey))
if err != nil {
return nil, err
}

// no legacy found
if len(data) == 0 {
bhl, err := NewBlockHashList(bs.backend, bs.rootAddress, BlockHashListCapacity)
if err != nil {
return nil, err
}
if bhl.IsEmpty() {
err = bhl.Push(
types.GenesisBlock(bs.chainID).Height,
types.GenesisBlockHash(bs.chainID),
)
if err != nil {
return nil, err
}
}
return bhl, nil
}

legacy, err := types.NewBlockHashListFromEncoded(data)
if err != nil {
return nil, err
}

// migrate the data
bhl, err := NewBlockHashList(bs.backend, bs.rootAddress, BlockHashListCapacity)
if err != nil {
return nil, err
}
for i := uint64(0); i <= legacy.MaxAvailableHeight(); i++ {
// for the non-existing ones we insert empty hash
_, bh := legacy.BlockHashByHeight(i)
err = bhl.Push(i, bh)

if bhl.IsEmpty() {
err = bhl.Push(
types.GenesisBlock(bs.chainID).Height,
types.GenesisBlockHash(bs.chainID),
)
if err != nil {
return nil, err
}
}

// reset the old key
err = bs.backend.SetValue(bs.rootAddress[:], []byte(BlockStoreBlockHashesKey), nil)
if err != nil {
return nil, err
}

return bhl, nil
}
Loading

0 comments on commit bb5d146

Please sign in to comment.