Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pavel/p2p-get-pee…
Browse files Browse the repository at this point in the history
…rs-excl-self
  • Loading branch information
algorandskiy committed Oct 29, 2024
2 parents 23c611a + eff5fb4 commit e2adb71
Show file tree
Hide file tree
Showing 66 changed files with 1,396 additions and 605 deletions.
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ executors:
macos:
xcode: 14.2.0
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: "true"
mac_arm64_large:
macos:
xcode: 14.2.0
resource_class: macos.m1.large.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: "true"

slack-fail-stop-step: &slack-fail-post-step
post-steps:
Expand Down
1 change: 0 additions & 1 deletion .golangci-warnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ linters:
enable:
- gosec
- partitiontest
- unused

linters-settings:
gosec: # we are mostly only interested in G601
Expand Down
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- staticcheck
- typecheck
- paralleltest
- unused

severity:
default-severity: error
Expand Down Expand Up @@ -115,6 +116,14 @@ issues:
- "^superfluous-else: if block ends with"

exclude-rules:
- path: cmd/algofix/
linters: unused
- path: cmd/algocfg/
linters: unused
- path: cmd/catchpointdump/
linters: unused
- path: tools/
linters: unused
- path: _test\.go
linters:
- errcheck
Expand All @@ -129,6 +138,7 @@ issues:
# - revive
# - staticcheck
- typecheck
- unused
- path: _test\.go
linters:
- staticcheck
Expand Down Expand Up @@ -206,3 +216,4 @@ issues:
- govet
- ineffassign
- misspell
- unused
205 changes: 87 additions & 118 deletions README.md

Large diffs are not rendered by default.

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
5 changes: 3 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ func TestLocal_ValidateP2PHybridConfig(t *testing.T) {

for i, test := range tests {
test := test
t.Run(fmt.Sprintf("test=%d", i), func(t *testing.T) {
name := fmt.Sprintf("test=%d", i)
t.Run(name, func(t *testing.T) {
t.Parallel()

c := Local{
Expand All @@ -782,7 +783,7 @@ func TestLocal_ValidateP2PHybridConfig(t *testing.T) {
NetAddress: test.netAddress,
}
err := c.ValidateP2PHybridConfig()
require.Equal(t, test.err, err != nil, "test=%d", i)
require.Equal(t, test.err, err != nil, name)
})
}
}
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
3 changes: 3 additions & 0 deletions config/localTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ type Local struct {
// EndpointAddress configures the address the node listens to for REST API calls. Specify an IP and port or just port. For example, 127.0.0.1:0 will listen on a random port on the localhost (preferring 8080).
EndpointAddress string `version[0]:"127.0.0.1:0"`

// Respond to Private Network Access preflight requests sent to the node. Useful when a public website is trying to access a node that's hosted on a local network.
EnablePrivateNetworkAccessHeader bool `version[34]:"false"`

// RestReadTimeoutSeconds is passed to the API servers rest http.Server implementation.
RestReadTimeoutSeconds int `version[4]:"15"`

Expand Down
1 change: 1 addition & 0 deletions config/local_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var defaultLocal = Local{
EnableP2P: false,
EnableP2PHybridMode: false,
EnablePingHandler: true,
EnablePrivateNetworkAccessHeader: false,
EnableProcessBlockStats: false,
EnableProfiler: false,
EnableRequestLogger: false,
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const VersionMajor = 3

// VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced.
// Not enforced until after initial public release (x > 0).
const VersionMinor = 26
const VersionMinor = 27

// Version is the type holding our full version information.
type Version struct {
Expand Down
20 changes: 0 additions & 20 deletions daemon/algod/api/client/restClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,6 @@ type pendingTransactionsByAddrParams struct {
Max uint64 `url:"max"`
}

type transactionsByAddrParams struct {
FirstRound uint64 `url:"firstRound"`
LastRound uint64 `url:"lastRound"`
Max uint64 `url:"max"`
}

type assetsParams struct {
AssetIdx uint64 `url:"assetIdx"`
Max uint64 `url:"max"`
}

type appsParams struct {
AppIdx uint64 `url:"appIdx"`
Max uint64 `url:"max"`
}

type rawblockParams struct {
Raw uint64 `url:"raw"`
}

type rawFormat struct {
Format string `url:"format"`
}
Expand Down
13 changes: 13 additions & 0 deletions daemon/algod/api/server/lib/middlewares/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ func MakeCORS(tokenHeader string) echo.MiddlewareFunc {
AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodOptions},
})
}

// MakePNA constructs the Private Network Access middleware function
func MakePNA() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
req := ctx.Request()
if req.Method == http.MethodOptions && req.Header.Get("Access-Control-Request-Private-Network") == "true" {
ctx.Response().Header().Set("Access-Control-Allow-Private-Network", "true")
}
return next(ctx)
}
}
}
Loading

0 comments on commit e2adb71

Please sign in to comment.