Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FVM] reducing register touches #2502

Merged
merged 35 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
05e96a6
add account status
ramtinms May 26, 2022
33a5e1a
remove old migration codes
ramtinms May 26, 2022
fb2cb71
add account status migration
ramtinms May 26, 2022
0db4cd0
remove onhold status
ramtinms May 26, 2022
3ee8b00
no need for account freeze enabler anymore
ramtinms May 26, 2022
001695e
account freezing disabled by the context
ramtinms May 26, 2022
64a43b1
update migrations and remove depricated keys
ramtinms May 26, 2022
a85a535
merge FrozenChecker into TxVerifier
ramtinms May 26, 2022
8ba25f1
optimize get contract to load less register on happy path
ramtinms May 26, 2022
9284151
remove unused methods
ramtinms May 27, 2022
480b19d
format imports
ramtinms May 30, 2022
58b7f5d
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms May 30, 2022
15a2be8
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms May 30, 2022
aceb91a
update tests
ramtinms Jun 2, 2022
8295c41
reduce key prefix size
ramtinms Jun 2, 2022
a0cda92
fix linter
ramtinms Jun 3, 2022
80005ad
update tests
ramtinms Jun 4, 2022
055be62
update storage used after migration
ramtinms Jun 4, 2022
5f63bc3
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 4, 2022
5c1d879
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 7, 2022
6672c31
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 9, 2022
d9fd0a1
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 21, 2022
65dc33f
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 21, 2022
27e2cec
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 21, 2022
c38f3e9
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 22, 2022
70cbbf8
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 22, 2022
e412b5d
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 22, 2022
eea22d7
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 22, 2022
c53cf6c
Merge branch 'master' into ramtin/2492-revamp-account-registers
m4ksio Jun 23, 2022
964cbf4
Ensure transaction executed successfully
m4ksio Jun 23, 2022
36fb7f2
comment out the regression part for now
ramtinms Jun 24, 2022
2b25ed2
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 24, 2022
228f280
update test to support Epoch Tx
ramtinms Jun 27, 2022
9d429be
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 27, 2022
02c16e8
Merge branch 'master' into ramtin/2492-revamp-account-registers
ramtinms Jun 27, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ func extractExecutionState(
OutputDir: outputDir,
}

orderedMapMigration := mgr.OrderedMapMigration{
Log: log,
OutputDir: dir,
accountStatusMigration := mgr.AccountStatusMigration{
Logger: log,
}

migrations = []ledger.Migration{
orderedMapMigration.Migrate,
accountStatusMigration.Migrate,
storageUsedUpdateMigration.Migrate,
ramtinms marked this conversation as resolved.
Show resolved Hide resolved
mgr.PruneMigration,
}
Expand Down
50 changes: 50 additions & 0 deletions cmd/util/ledger/migrations/account_status_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package migrations

import (
"encoding/hex"

"github.com/rs/zerolog"

"github.com/onflow/flow-go/fvm/state"
"github.com/onflow/flow-go/ledger"
)

const (
KeyExists = "exists"
KeyAccountFrozen = "frozen"
)

// AccountStatusMigration migrates previous registers under
// key of Exists which were used for checking existance of accounts.
// the new register AccountStatus also captures frozen and all future states
// of the accounts. Frozen state is used when an account is set
// by the network governance for furture investigation and prevents operations on the account until
// furthure investigation by the community.
// This migration assumes no account has been frozen until now, and would warn if
// find any account with frozen flags.
type AccountStatusMigration struct {
Logger zerolog.Logger
}

func (as *AccountStatusMigration) Migrate(payload []ledger.Payload) ([]ledger.Payload, error) {
newPayloads := make([]ledger.Payload, 0, len(payload))
for _, p := range payload {
owner := p.Key.KeyParts[0].Value
controller := p.Key.KeyParts[1].Value
key := p.Key.KeyParts[2].Value
if len(controller) == 0 && string(key) == KeyExists {
newPayload := p.DeepCopy()
newPayload.Key.KeyParts[2].Value = []byte(state.KeyAccountStatus)
newPayload.Value = state.NewAccountStatus().ToBytes()
newPayloads = append(newPayloads, *newPayload)
continue
}
if len(controller) == 0 && string(key) == KeyAccountFrozen {
as.Logger.Warn().Msgf("frozen account found: %s", hex.EncodeToString(owner))
continue
}
// else just append and continue
newPayloads = append(newPayloads, p)
}
return newPayloads, nil
}
55 changes: 55 additions & 0 deletions cmd/util/ledger/migrations/account_status_migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package migrations

import (
"testing"

"github.com/rs/zerolog"
"github.com/stretchr/testify/require"

"github.com/onflow/flow-go-sdk"

state "github.com/onflow/flow-go/fvm/state"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/ledger/common/utils"
)

func createAccountPayloadKey(a flow.Address, key string) ledger.Key {
return ledger.Key{
KeyParts: []ledger.KeyPart{
ledger.NewKeyPart(0, a.Bytes()),
ledger.NewKeyPart(1, []byte("")),
ledger.NewKeyPart(2, []byte(key)),
},
}
}

func TestAccountStatusMigration(t *testing.T) {
mig := AccountStatusMigration{
Logger: zerolog.Logger{},
}

address1 := flow.HexToAddress("0x1")
address2 := flow.HexToAddress("0x2")

payloads := []ledger.Payload{
{Key: createAccountPayloadKey(address1, state.KeyStorageUsed), Value: utils.Uint64ToBinary(1)},
{Key: createAccountPayloadKey(address1, "other registers"), Value: utils.Uint64ToBinary(2)},
{Key: createAccountPayloadKey(address2, "other registers2"), Value: utils.Uint64ToBinary(3)},
{Key: createAccountPayloadKey(address1, KeyExists), Value: []byte{1}},
{Key: createAccountPayloadKey(address1, KeyAccountFrozen), Value: []byte{1}},
}

newPayloads, err := mig.Migrate(payloads)
require.NoError(t, err)
require.Equal(t, 4, len(newPayloads)) // no more frozen register

require.True(t, newPayloads[0].Equals(&payloads[0]))
require.True(t, newPayloads[1].Equals(&payloads[1]))
require.True(t, newPayloads[2].Equals(&payloads[2]))

expectedPayload := &ledger.Payload{
Key: createAccountPayloadKey(address1, state.KeyAccountStatus),
Value: state.NewAccountStatus().ToBytes(),
}
require.True(t, newPayloads[3].Equals(expectedPayload))
}
258 changes: 0 additions & 258 deletions cmd/util/ledger/migrations/ordered_map_migration.go

This file was deleted.

Loading