Skip to content

Commit

Permalink
revert back to custom upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Nov 21, 2024
1 parent fd270d7 commit 46e5bb9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
12 changes: 4 additions & 8 deletions integration/tests/upgrades/protocol_version_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ func TestProtocolVersionUpgrade(t *testing.T) {
suite.Run(t, new(ProtocolVersionUpgradeSuite))
}

func (suite *ProtocolVersionUpgradeSuite) SetupTest() {
suite.Suite.SetupTest()
func (s *ProtocolVersionUpgradeSuite) SetupTest() {
// Begin the test with a v0 kvstore, rather than the default v1.
// This lets us test upgrading v0->v1
protocolState, err := suite.net.BootstrapSnapshot.ProtocolState()
require.NoError(suite.T(), err)
finalizationThreshold := protocolState.GetFinalizationSafetyThreshold()
epochExtensionViewCount := protocolState.GetEpochExtensionViewCount()
suite.KVStoreFactory = func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error) {
return kvstore.NewKVStoreV0(finalizationThreshold, epochExtensionViewCount, epochStateID)
s.KVStoreFactory = func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error) {
return kvstore.NewKVStoreV0(5, 100, epochStateID)
}
s.Suite.SetupTest()
}

// TestProtocolStateVersionUpgradeServiceEvent tests the process of upgrading the protocol
Expand Down
29 changes: 29 additions & 0 deletions integration/utils/templates/set-protocol-state-version.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import NodeVersionBeacon from "NodeVersionBeacon"

/// Transaction that allows NodeVersionAdmin to specify a new protocol state version.
/// The new version will become active at view `activeView` if the service event
/// is processed and applied to the protocol state within a block `B` such that
/// `B.view + ∆ < activeView`, for a protocol-defined safety threshold ∆.
/// Service events not meeting this threshold are discarded.
///
/// This is a special version of the admin transaction for use in integration tests.
/// We allow the sender to pass in a value to add to the current view, to reduce
/// the liklihood that a test spuriously fails due to timing.
transaction(newProtocolVersion: UInt64, activeViewDiff: UInt64) {

let adminRef: &NodeVersionBeacon.Admin

prepare(acct: auth(BorrowValue) &Account) {
// Borrow a reference to the NodeVersionAdmin implementing resource
self.adminRef = acct.storage.borrow<&NodeVersionBeacon.Admin>(from: NodeVersionBeacon.AdminStoragePath)
?? panic("Couldn't borrow NodeVersionBeacon.Admin Resource")
}

execute {
let block = getCurrentBlock()
self.adminRef.emitProtocolStateVersionUpgrade(
newProtocolVersion: newProtocolVersion,
activeView: block.view + activeViewDiff
)
}
}
5 changes: 4 additions & 1 deletion integration/utils/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var createAndSetupNodeTxScript string
//go:embed templates/remove-node.cdc
var removeNodeTxScript string

//go:embed "templates/set-protocol-state-version.cdc"
var setProtocolStateVersionScript string

func LocalnetEnv() templates.Environment {
return templates.Environment{
EpochAddress: "f8d6e0586b0a20c7",
Expand Down Expand Up @@ -194,7 +197,7 @@ func MakeSetProtocolStateVersionTx(
accountKey := adminAccount.Keys[adminAccountKeyID]

tx := sdk.NewTransaction().
SetScript(templates.GenerateSetProtocolStateVersionScript(env)).
SetScript([]byte(templates.ReplaceAddresses(setProtocolStateVersionScript, env))).
SetComputeLimit(9999).
SetReferenceBlockID(latestBlockID).
SetProposalKey(adminAccount.Address, adminAccountKeyID, accountKey.SequenceNumber).
Expand Down

0 comments on commit 46e5bb9

Please sign in to comment.