Skip to content

Commit

Permalink
Consensus: For Devnet and Betanet, support custom network upgrade del…
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalouf authored Oct 11, 2024
1 parent cb4de53 commit c9000bf
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/algod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func run() int {
log.Fatalf("Error validating DNSBootstrap input: %v", err)
}

// Apply network-specific consensus overrides, noting the configurable consensus protocols file
// takes precedence over network-specific overrides.
config.ApplyShorterUpgradeRoundsForDevNetworks(genesis.Network)

err = config.LoadConfigurableConsensusProtocols(absolutePath)
if err != nil {
// log is not setup yet, this will log to stderr
Expand Down
17 changes: 17 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,23 @@ func initConsensusProtocols() {
vAlpha4.ApprovedUpgrades[protocol.ConsensusVAlpha5] = 10000
}

// ApplyShorterUpgradeRoundsForDevNetworks applies a shorter upgrade round time for the Devnet and Betanet networks.
// This function should not take precedence over settings loaded via `PreloadConfigurableConsensusProtocols`.
func ApplyShorterUpgradeRoundsForDevNetworks(id protocol.NetworkID) {
if id == Betanet || id == Devnet {
// Go through all approved upgrades and set to the MinUpgradeWaitRounds valid where MinUpgradeWaitRounds is set
for _, p := range Consensus {
if p.ApprovedUpgrades != nil {
for v := range p.ApprovedUpgrades {
if p.MinUpgradeWaitRounds > 0 {
p.ApprovedUpgrades[v] = p.MinUpgradeWaitRounds
}
}
}
}
}
}

// Global defines global Algorand protocol parameters which should not be overridden.
type Global struct {
SmallLambda time.Duration // min amount of time to wait for leader's credential (i.e., time to propagate one credential)
Expand Down
77 changes: 77 additions & 0 deletions config/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,83 @@ func TestConsensusUpgradeWindow(t *testing.T) {
}
}

func TestConsensusUpgradeWindow_NetworkOverrides(t *testing.T) {
partitiontest.PartitionTest(t)

ApplyShorterUpgradeRoundsForDevNetworks(Devnet)
for _, params := range Consensus {
for toVersion, delay := range params.ApprovedUpgrades {
if params.MinUpgradeWaitRounds != 0 || params.MaxUpgradeWaitRounds != 0 {
require.NotZerof(t, delay, "From :%v\nTo :%v", params, toVersion)
require.Equalf(t, delay, params.MinUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
// This check is not really needed, but leaving for sanity
require.LessOrEqualf(t, delay, params.MaxUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
} else {
// If no MinUpgradeWaitRounds is set, leaving everything as zero value is expected
require.Zerof(t, delay, "From :%v\nTo :%v", params, toVersion)
}
}
}

// Should be no-ops for Mainnet
Consensus = make(ConsensusProtocols)
initConsensusProtocols()

origConsensus := Consensus.DeepCopy()
ApplyShorterUpgradeRoundsForDevNetworks(Mainnet)
require.EqualValues(t, origConsensus, Consensus)
for _, params := range Consensus {
for toVersion, delay := range params.ApprovedUpgrades {
if params.MinUpgradeWaitRounds != 0 || params.MaxUpgradeWaitRounds != 0 {
require.NotZerof(t, delay, "From :%v\nTo :%v", params, toVersion)
require.GreaterOrEqualf(t, delay, params.MinUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
require.LessOrEqualf(t, delay, params.MaxUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
} else {
require.Zerof(t, delay, "From :%v\nTo :%v", params, toVersion)

}
}
}

// reset consensus settings
Consensus = make(ConsensusProtocols)
initConsensusProtocols()

ApplyShorterUpgradeRoundsForDevNetworks(Betanet)
for _, params := range Consensus {
for toVersion, delay := range params.ApprovedUpgrades {
if params.MinUpgradeWaitRounds != 0 || params.MaxUpgradeWaitRounds != 0 {
require.NotZerof(t, delay, "From :%v\nTo :%v", params, toVersion)
require.Equalf(t, delay, params.MinUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
// This check is not really needed, but leaving for sanity
require.LessOrEqualf(t, delay, params.MaxUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
} else {
// If no MinUpgradeWaitRounds is set, leaving everything as zero value is expected
require.Zerof(t, delay, "From :%v\nTo :%v", params, toVersion)
}
}
}

// should be no-ops for Testnet
Consensus = make(ConsensusProtocols)
initConsensusProtocols()

ApplyShorterUpgradeRoundsForDevNetworks(Testnet)
require.EqualValues(t, origConsensus, Consensus)
for _, params := range Consensus {
for toVersion, delay := range params.ApprovedUpgrades {
if params.MinUpgradeWaitRounds != 0 || params.MaxUpgradeWaitRounds != 0 {
require.NotZerof(t, delay, "From :%v\nTo :%v", params, toVersion)
require.GreaterOrEqualf(t, delay, params.MinUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
require.LessOrEqualf(t, delay, params.MaxUpgradeWaitRounds, "From :%v\nTo :%v", params, toVersion)
} else {
require.Zerof(t, delay, "From :%v\nTo :%v", params, toVersion)

}
}
}
}

func TestConsensusStateProofParams(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down

0 comments on commit c9000bf

Please sign in to comment.