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

Update atree inlining for Cadence 1.0 feature branch #6127

Merged
merged 14 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
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
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
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 @@ -1274,6 +1274,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
42 changes: 42 additions & 0 deletions state/protocol/events/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package events

import (
"github.com/rs/zerolog"

"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
)

type EventLogger struct {
Noop // satisfy protocol events consumer interface
logger zerolog.Logger
}

var _ protocol.Consumer = (*EventLogger)(nil)

func NewEventLogger(logger zerolog.Logger) *EventLogger {
return &EventLogger{
logger: logger.With().Str("module", "protocol_events_logger").Logger(),
}
}

func (p EventLogger) EpochTransition(newEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("newEpochCounter", newEpochCounter).
Uint64("height", header.Height).
Uint64("view", header.View).
Msg("epoch transition")
}

func (p EventLogger) EpochSetupPhaseStarted(currentEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("currentEpochCounter", currentEpochCounter).
Uint64("height", header.Height).
Uint64("view", header.View).
Msg("epoch setup phase started")
}

func (p EventLogger) EpochCommittedPhaseStarted(currentEpochCounter uint64, header *flow.Header) {
p.logger.Info().Uint64("currentEpochCounter", currentEpochCounter).
Uint64("height", header.Height).
Uint64("view", header.View).
Msg("epoch committed phase started")
}
Loading