Skip to content

Commit

Permalink
update efm integration ensure we transition into recovery epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
kc1116 committed Aug 30, 2024
1 parent caf4d65 commit 5e6f908
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 24 deletions.
10 changes: 6 additions & 4 deletions cmd/bootstrap/run/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func GenerateRecoverEpochTxArgs(log zerolog.Logger,
internalNodePrivInfoDir string,
nodeConfigJson string,
collectionClusters int,
epochCounter uint64,
recoveryEpochCounter uint64,
rootChainID flow.ChainID,
numViewsInStakingAuction uint64,
numViewsInEpoch uint64,
targetDuration uint64,
initNewEpoch bool,
unsafeAllowOverWrite bool,
snapshot *inmem.Snapshot,
) ([]cadence.Value, error) {
epoch := snapshot.Epochs().Current()
Expand Down Expand Up @@ -83,7 +83,7 @@ func GenerateRecoverEpochTxArgs(log zerolog.Logger,
log.Info().Msg("")

log.Info().Msg("constructing root blocks for collection node clusters")
clusterBlocks := GenerateRootClusterBlocks(epochCounter, clusters)
clusterBlocks := GenerateRootClusterBlocks(recoveryEpochCounter, clusters)
log.Info().Msg("")

log.Info().Msg("constructing root QCs for collection node clusters")
Expand Down Expand Up @@ -135,6 +135,8 @@ func GenerateRecoverEpochTxArgs(log zerolog.Logger,
}

args := []cadence.Value{
// recovery epoch counter
cadence.NewUInt64(recoveryEpochCounter),
// epoch start view
cadence.NewUInt64(currEpochFinalView + 1),
// staking phase end view
Expand All @@ -155,7 +157,7 @@ func GenerateRecoverEpochTxArgs(log zerolog.Logger,
cadence.NewArray(nodeIds),
// recover the network by initializing a new recover epoch which will increment the smart contract epoch counter
// or overwrite the epoch metadata for the current epoch
cadence.NewBool(initNewEpoch),
cadence.NewBool(unsafeAllowOverWrite),
}

return args, nil
Expand Down
13 changes: 9 additions & 4 deletions cmd/util/cmd/epochs/cmd/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ This recovery process has some constraints:
flagNumViewsInStakingAuction uint64
flagEpochCounter uint64
flagTargetDuration uint64
flagInitNewEpoch bool
flagRecoveryEpochCounter uint64
flagUnsafeAllowOverWrite bool
flagRootChainID string
)

Expand Down Expand Up @@ -82,7 +83,8 @@ func addGenerateRecoverEpochTxArgsCmdFlags() error {
// This is needed only if a previous recoverEpoch transaction was submitted and a race condition occurred such that:
// - the RecoveryEpoch in the admin transaction was accepted by the smart contract
// - the RecoveryEpoch service event (after sealing latency) was rejected by the Protocol State
generateRecoverEpochTxArgsCmd.Flags().BoolVar(&flagInitNewEpoch, "unsafe-overwrite-epoch-data", false, "set to true if the resulting transaction is allowed to overwrite an already specified epoch in the smart contract.")
generateRecoverEpochTxArgsCmd.Flags().BoolVar(&flagUnsafeAllowOverWrite, "unsafe-overwrite-epoch-data", false, "set to true if the resulting transaction is allowed to overwrite an already specified epoch in the smart contract.")
generateRecoverEpochTxArgsCmd.Flags().Uint64Var(&flagEpochCounter, "recovery-epoch-counter", 0, "the recovery epoch counter")

err := generateRecoverEpochTxArgsCmd.MarkFlagRequired("access-address")
if err != nil {
Expand All @@ -108,11 +110,14 @@ func addGenerateRecoverEpochTxArgsCmdFlags() error {
if err != nil {
return fmt.Errorf("failed to mark epoch-timing-duration flag as required")
}

err = generateRecoverEpochTxArgsCmd.MarkFlagRequired("root-chain-id")
if err != nil {
return fmt.Errorf("failed to mark root-chain-id flag as required")
}
err = generateRecoverEpochTxArgsCmd.MarkFlagRequired("recovery-epoch-counter")
if err != nil {
return fmt.Errorf("failed to mark recovery-epoch-counter flag as required")
}
return nil
}

Expand Down Expand Up @@ -150,7 +155,7 @@ func generateRecoverEpochTxArgs(getSnapshot func() *inmem.Snapshot) func(cmd *co
flagNumViewsInStakingAuction,
flagNumViewsInEpoch,
flagTargetDuration,
flagInitNewEpoch,
flagUnsafeAllowOverWrite,
getSnapshot(),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/cmd/epochs/cmd/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestRecoverEpochHappyPath(t *testing.T) {
_, ok := allNodeIdsCdc[nodeId.(cadence.String)]
require.True(t, ok)
}
// initNewEpoch
// unsafeAllowOverWrite
require.Equal(t, decodedValues[9], cadence.NewBool(false))
})
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ require (
github.com/onflow/cadence v1.0.0-preview.34
github.com/onflow/crypto v0.25.1
github.com/onflow/flow v0.3.4
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698
github.com/onflow/flow-go-sdk v1.0.0-preview.36
github.com/onflow/flow/protobuf/go/flow v0.4.4
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2180,8 +2180,12 @@ github.com/onflow/flow v0.3.4 h1:FXUWVdYB90f/rjNcY0Owo30gL790tiYff9Pb/sycXYE=
github.com/onflow/flow v0.3.4/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920 h1:dvpU5WG++j9s3XXbFnMv/eVdupEHh1Xb0NyLZYDEz7A=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698 h1:8XP4+w/4aUy2j44LNE9w55Z7orPJDvlYjSXvBIPayaM=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920 h1:SBUd8cq9OThExucjUO3EFMuzA5Sp8NLGUjch2phxKfg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698 h1:zjlLCAAx4qrurQaJ5SQdAZWqGA9V6yUkueyYCsl/Y8k=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs=
Expand Down
4 changes: 2 additions & 2 deletions insecure/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.7.0-rc.2 // indirect
github.com/onflow/cadence v1.0.0-preview.34 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698 // indirect
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 // indirect
github.com/onflow/flow-ft/lib/go/templates v1.0.0 // indirect
github.com/onflow/flow-go-sdk v1.0.0-preview.36 // indirect
Expand Down
4 changes: 4 additions & 0 deletions insecure/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2167,8 +2167,12 @@ github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920 h1:dvpU5WG++j9s3XXbFnMv/eVdupEHh1Xb0NyLZYDEz7A=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698 h1:8XP4+w/4aUy2j44LNE9w55Z7orPJDvlYjSXvBIPayaM=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920 h1:SBUd8cq9OThExucjUO3EFMuzA5Sp8NLGUjch2phxKfg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698 h1:zjlLCAAx4qrurQaJ5SQdAZWqGA9V6yUkueyYCsl/Y8k=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs=
Expand Down
4 changes: 2 additions & 2 deletions integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ require (
github.com/libp2p/go-libp2p v0.32.2
github.com/onflow/cadence v1.0.0-preview.34
github.com/onflow/crypto v0.25.1
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698
github.com/onflow/flow-emulator v1.0.0-preview.24
github.com/onflow/flow-go v0.35.5-0.20240517202625-55f862b45dfd
github.com/onflow/flow-go-sdk v1.0.0-preview.36
Expand Down
4 changes: 4 additions & 0 deletions integration/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2157,8 +2157,12 @@ github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920 h1:dvpU5WG++j9s3XXbFnMv/eVdupEHh1Xb0NyLZYDEz7A=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698 h1:8XP4+w/4aUy2j44LNE9w55Z7orPJDvlYjSXvBIPayaM=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920 h1:SBUd8cq9OThExucjUO3EFMuzA5Sp8NLGUjch2phxKfg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.1-0.20240710025346-d8135ebb9920/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698 h1:zjlLCAAx4qrurQaJ5SQdAZWqGA9V6yUkueyYCsl/Y8k=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.2-0.20240801155508-9f8ceed15698/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-emulator v1.0.0-preview.24 h1:SonXMBeYxVwNn94M+OUmKIYScIMQG22wugh9n/tHY5k=
github.com/onflow/flow-emulator v1.0.0-preview.24/go.mod h1:QprPouTWO3iv9VF/y4Ksltv2XIbzNMzjjr5zzq51i7Q=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0=
Expand Down
14 changes: 12 additions & 2 deletions integration/tests/epochs/recover_epoch/recover_epoch_efm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"testing"
"time"

"github.com/onflow/cadence"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

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

"github.com/onflow/flow-go/integration/utils"
"github.com/onflow/flow-go/model/flow"
)
Expand Down Expand Up @@ -71,7 +73,8 @@ func (s *RecoverEpochSuite) TestRecoverEpoch() {
// cruise control is disabled for integration tests
// targetDuration and targetEndTime will be ignored
3000,
4000,
// unsafeAllowOverWrite set to false, initialize new epoch
false,
)

// 3. Submit recover epoch transaction to the network.
Expand All @@ -94,5 +97,12 @@ func (s *RecoverEpochSuite) TestRecoverEpoch() {
require.NoError(s.T(), err)
require.Equal(s.T(), events[0].Events[0].Type, eventType)

// 4. TODO(EFM, #6164) ensure EpochRecover service event is processed by the fallback state machine and the network recovers.
startViewOfNextEpoch := uint64(txArgs[1].(cadence.UInt64))
// wait for first view of recovery epoch
s.TimedLogf("waiting to transition into recovery epoch (finalized view %d)", startViewOfNextEpoch)
s.AwaitFinalizedView(s.Ctx, startViewOfNextEpoch, 2*time.Minute, 500*time.Millisecond)
s.TimedLogf("observed finalized first view of recovery epoch %d", startViewOfNextEpoch)

// ensure we transition into recovery epoch
s.AssertInEpoch(s.Ctx, 1)
}
12 changes: 9 additions & 3 deletions integration/tests/epochs/recover_epoch/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ func (s *Suite) getNodeInfoDirs(role flow.Role) (string, string) {
// Returns:
//
// []cadence.Value: the transaction arguments.
func (s *Suite) executeEFMRecoverTXArgsCMD(collectionClusters int, numViewsInEpoch, numViewsInStakingAuction, epochCounter, targetDuration, targetEndTime uint64) []cadence.Value {
func (s *Suite) executeEFMRecoverTXArgsCMD(
collectionClusters int,
numViewsInEpoch,
numViewsInStakingAuction,
recoveryEpochCounter,
targetDuration uint64,
unsafeAllowOverWrite bool) []cadence.Value {
// read internal node info from one of the consensus nodes
internalNodePrivInfoDir, nodeConfigJson := s.getNodeInfoDirs(flow.RoleConsensus)
snapshot := s.GetLatestProtocolSnapshot(s.Ctx)
Expand All @@ -65,12 +71,12 @@ func (s *Suite) executeEFMRecoverTXArgsCMD(collectionClusters int, numViewsInEpo
internalNodePrivInfoDir,
nodeConfigJson,
collectionClusters,
epochCounter,
recoveryEpochCounter,
flow.Localnet,
numViewsInStakingAuction,
numViewsInEpoch,
targetDuration,
false,
unsafeAllowOverWrite,
snapshot,
)
require.NoError(s.T(), err)
Expand Down
8 changes: 4 additions & 4 deletions model/convert/service_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package convert
import (
"encoding/hex"
"fmt"
"strings"

"github.com/coreos/go-semver/semver"
"github.com/onflow/cadence"
Expand Down Expand Up @@ -761,8 +762,7 @@ func convertClusterQCVoteData(cdcClusterQCVoteData []cadence.Value) ([]flow.Clus
if err != nil {
return nil, fmt.Errorf("failed to decode clusterQCVoteData struct: %w", err)
}

aggregatedSignature, err := hex.DecodeString(string(cdcAggSignature))
aggregatedSignature, err := hex.DecodeString(strings.ReplaceAll(string(cdcAggSignature), "0x", ""))
if err != nil {
return nil, fmt.Errorf("could not convert raw vote from hex: %w", err)
}
Expand Down Expand Up @@ -963,7 +963,7 @@ func convertDKGKeys(cdcDKGKeys []cadence.Value) (
hexDKGKeys = hexDKGKeys[1:]

// decode group public key
groupKeyBytes, err := hex.DecodeString(groupPubKeyHex)
groupKeyBytes, err := hex.DecodeString(strings.ReplaceAll(groupPubKeyHex, "0x", ""))
if err != nil {
return nil, nil, fmt.Errorf(
"could not decode group public key into bytes: %w",
Expand All @@ -979,7 +979,7 @@ func convertDKGKeys(cdcDKGKeys []cadence.Value) (
dkgParticipantKeys := make([]crypto.PublicKey, 0, len(hexDKGKeys))
for _, pubKeyString := range hexDKGKeys {

pubKeyBytes, err := hex.DecodeString(pubKeyString)
pubKeyBytes, err := hex.DecodeString(strings.ReplaceAll(pubKeyString, "0x", ""))
if err != nil {
return nil, nil, fmt.Errorf(
"could not decode individual public key into bytes: %w",
Expand Down

0 comments on commit 5e6f908

Please sign in to comment.