Skip to content

Commit

Permalink
Merge pull request #6127 from onflow/master
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Jun 19, 2024
2 parents 74a7cfd + 0c0c0d2 commit d2c4171
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 69 deletions.
36 changes: 19 additions & 17 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 90
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- Preserve
- Idea
# Label to use when marking an issue as stale
staleLabel: Stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
name: 'Mark and close stale issues'
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
days-before-issue-stale: 90
days-before-issue-close: 7
exempt-issue-labels: 'Preserve,Idea'
stale-issue-label: 'Stale'
stale-issue-message: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
5 changes: 5 additions & 0 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ func (fnb *FlowNodeBuilder) EnqueueNetworkInit() {
peerManagerFilters)
})

fnb.Module("epoch transition logger", func(node *NodeConfig) error {
node.ProtocolEvents.AddConsumer(events.NewEventLogger(node.Logger))
return nil
})

fnb.Module("network underlay dependency", func(node *NodeConfig) error {
fnb.networkUnderlayDependable = module.NewProxiedReadyDoneAware()
fnb.PeerManagerDependencies.Add(fnb.networkUnderlayDependable)
Expand Down
14 changes: 14 additions & 0 deletions cmd/util/cmd/diff-states/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
flagStateCommitment1 string
flagStateCommitment2 string
flagRaw bool
flagAlwaysDiffValues bool
flagNWorker int
flagChain string
)
Expand Down Expand Up @@ -113,6 +114,13 @@ func init() {
"Raw or value",
)

Cmd.Flags().BoolVar(
&flagAlwaysDiffValues,
"always-diff-values",
false,
"always diff on value level. useful when trying to test iteration, by diffing same state.",
)

Cmd.Flags().IntVar(
&flagNWorker,
"n-worker",
Expand Down Expand Up @@ -294,6 +302,8 @@ func diffAccount(
})
}

diffValues := flagAlwaysDiffValues

err = accountRegisters1.ForEach(func(owner, key string, value1 []byte) error {
var value2 []byte
value2, err = accountRegisters2.Get(owner, key)
Expand Down Expand Up @@ -323,6 +333,10 @@ func diffAccount(
return err
}

diffValues = true
}

if diffValues {
address, err := common.BytesToAddress([]byte(owner))
if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path"
"runtime/pprof"
"strings"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -178,6 +179,20 @@ func init() {
}

func run(*cobra.Command, []string) {
if flagCPUProfile != "" {
f, err := os.Create(flagCPUProfile)
if err != nil {
log.Fatal().Err(err).Msg("could not create CPU profile")
}

err = pprof.StartCPUProfile(f)
if err != nil {
log.Fatal().Err(err).Msg("could not start CPU profile")
}

defer pprof.StopCPUProfile()
}

var stateCommitment flow.StateCommitment

if len(flagBlockHash) > 0 && len(flagStateCommitment) > 0 {
Expand Down
14 changes: 0 additions & 14 deletions cmd/util/cmd/execution-state-extract/execution_state_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"math"
"os"
"runtime/pprof"
syncAtomic "sync/atomic"
"time"

Expand Down Expand Up @@ -325,19 +324,6 @@ func newMigration(
nWorker int,
) ledger.Migration {
return func(payloads []*ledger.Payload) ([]*ledger.Payload, error) {
if flagCPUProfile != "" {
f, err := os.Create(flagCPUProfile)
if err != nil {
logger.Fatal().Err(err).Msg("could not create CPU profile")
}

err = pprof.StartCPUProfile(f)
if err != nil {
logger.Fatal().Err(err).Msg("could not start CPU profile")
}

defer pprof.StopCPUProfile()
}

if len(migrations) == 0 {
return payloads, nil
Expand Down
10 changes: 10 additions & 0 deletions cmd/util/ledger/migrations/cadence_values_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,16 @@ func TestProgramParsingError(t *testing.T) {
)
require.NoError(t, err)

encodedContractNames, err := environment.EncodeContractNames([]string{contractName})
require.NoError(t, err)

err = registersByAccount.Set(
string(testAddress[:]),
flow.ContractNamesKey,
encodedContractNames,
)
require.NoError(t, err)

// Migrate

// TODO: EVM contract is not deployed in snapshot yet, so can't update it
Expand Down
60 changes: 39 additions & 21 deletions cmd/util/ledger/migrations/contract_checking_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util/registers"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/model/flow"
)

Expand All @@ -30,6 +31,7 @@ func NewContractCheckingMigration(
return func(registersByAccount *registers.ByAccount) error {

reporter := rwf.ReportWriter(contractCheckingReporterName)
defer reporter.Close()

mr, err := NewInterpreterMigrationRuntime(
registersByAccount,
Expand All @@ -42,6 +44,8 @@ func NewContractCheckingMigration(

// Gather all contracts

log.Info().Msg("Gathering contracts ...")

contractsForPrettyPrinting := make(map[common.Location][]byte, contractCountEstimate)

type contract struct {
Expand All @@ -50,35 +54,49 @@ func NewContractCheckingMigration(
}
contracts := make([]contract, 0, contractCountEstimate)

err = registersByAccount.ForEach(func(owner string, key string, value []byte) error {
err = registersByAccount.ForEachAccount(func(accountRegisters *registers.AccountRegisters) error {
owner := accountRegisters.Owner()

// Skip payloads that are not contract code
contractName := flow.KeyContractName(key)
if contractName == "" {
return nil
encodedContractNames, err := accountRegisters.Get(owner, flow.ContractNamesKey)
if err != nil {
return err
}

address := common.Address([]byte(owner))
code := value
location := common.AddressLocation{
Address: address,
Name: contractName,
contractNames, err := environment.DecodeContractNames(encodedContractNames)
if err != nil {
return err
}

contracts = append(
contracts,
contract{
location: location,
code: code,
},
)
for _, contractName := range contractNames {

contractKey := flow.ContractKey(contractName)

code, err := accountRegisters.Get(owner, contractKey)
if err != nil {
return err
}

address := common.Address([]byte(owner))
location := common.AddressLocation{
Address: address,
Name: contractName,
}

contracts = append(
contracts,
contract{
location: location,
code: code,
},
)

contractsForPrettyPrinting[location] = code
contractsForPrettyPrinting[location] = code
}

return nil
})
if err != nil {
return fmt.Errorf("failed to iterate over registers: %w", err)
return fmt.Errorf("failed to get contracts of accounts: %w", err)
}

sort.Slice(contracts, func(i, j int) bool {
Expand All @@ -87,6 +105,8 @@ func NewContractCheckingMigration(
return a.location.ID() < b.location.ID()
})

log.Info().Msgf("Gathered all contracts (%d)", len(contracts))

// Check all contracts

for _, contract := range contracts {
Expand Down Expand Up @@ -134,8 +154,6 @@ func NewContractCheckingMigration(
}
}

reporter.Close()

return nil
}
}
Expand Down
43 changes: 29 additions & 14 deletions fvm/environment/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,20 @@ func (a *StatefulAccounts) setContract(
return nil
}

func EncodeContractNames(contractNames contractNames) ([]byte, error) {
var buf bytes.Buffer
cborEncoder := cbor.NewEncoder(&buf)
err := cborEncoder.Encode(contractNames)
if err != nil {
return nil, errors.NewEncodingFailuref(
err,
"cannot encode contract names: %s",
contractNames,
)
}
return buf.Bytes(), nil
}

func (a *StatefulAccounts) setContractNames(
contractNames contractNames,
address flow.Address,
Expand All @@ -443,16 +457,11 @@ func (a *StatefulAccounts) setContractNames(
if !ok {
return errors.NewAccountNotFoundError(address)
}
var buf bytes.Buffer
cborEncoder := cbor.NewEncoder(&buf)
err = cborEncoder.Encode(contractNames)

newContractNames, err := EncodeContractNames(contractNames)
if err != nil {
return errors.NewEncodingFailuref(
err,
"cannot encode contract names: %s",
contractNames)
return err
}
newContractNames := buf.Bytes()

id := flow.ContractNamesRegisterID(address)
prevContractNames, err := a.GetValue(id)
Expand Down Expand Up @@ -607,20 +616,26 @@ func (a *StatefulAccounts) getContractNames(
error,
) {
// TODO return fatal error if can't fetch
encContractNames, err := a.GetValue(flow.ContractNamesRegisterID(address))
encodedContractNames, err := a.GetValue(flow.ContractNamesRegisterID(address))
if err != nil {
return nil, fmt.Errorf("cannot get deployed contract names: %w", err)
}

return DecodeContractNames(encodedContractNames)
}

func DecodeContractNames(encodedContractNames []byte) ([]string, error) {
identifiers := make([]string, 0)
if len(encContractNames) > 0 {
buf := bytes.NewReader(encContractNames)
if len(encodedContractNames) > 0 {
buf := bytes.NewReader(encodedContractNames)
cborDecoder := cbor.NewDecoder(buf)
err = cborDecoder.Decode(&identifiers)
err := cborDecoder.Decode(&identifiers)
if err != nil {
return nil, fmt.Errorf(
"cannot decode deployed contract names %x: %w",
encContractNames,
err)
encodedContractNames,
err,
)
}
}
return identifiers, nil
Expand Down
3 changes: 0 additions & 3 deletions network/p2p/cache/protocol_state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func NewProtocolStateIDCache(
// and virtually latency free. However, we run data base queries and acquire locks here,
// which is undesired.
func (p *ProtocolStateIDCache) EpochTransition(newEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("newEpochCounter", newEpochCounter).Msg("epoch transition")
p.update(header.ID())
}

Expand All @@ -82,7 +81,6 @@ func (p *ProtocolStateIDCache) EpochTransition(newEpochCounter uint64, header *f
// and virtually latency free. However, we run data base queries and acquire locks here,
// which is undesired.
func (p *ProtocolStateIDCache) EpochSetupPhaseStarted(currentEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("currentEpochCounter", currentEpochCounter).Msg("epoch setup phase started")
p.update(header.ID())
}

Expand All @@ -94,7 +92,6 @@ func (p *ProtocolStateIDCache) EpochSetupPhaseStarted(currentEpochCounter uint64
// and virtually latency free. However, we run data base queries and acquire locks here,
// which is undesired.
func (p *ProtocolStateIDCache) EpochCommittedPhaseStarted(currentEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("currentEpochCounter", currentEpochCounter).Msg("epoch committed phase started")
p.update(header.ID())
}

Expand Down
Loading

0 comments on commit d2c4171

Please sign in to comment.