Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Oct 8, 2020
2 parents d183111 + bf00c3c commit f5fdb55
Show file tree
Hide file tree
Showing 54 changed files with 2,012 additions and 813 deletions.
13 changes: 11 additions & 2 deletions .ci/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ set -ev

bash <(curl -s https://codecov.io/bash)

FULL_COMMIT_HASH="$(git --git-dir="$AVALANCHE_HOME/.git" rev-parse HEAD)"
COMMIT="${FULL_COMMIT_HASH::8}"

AVALANCHE_IMAGE="$DOCKERHUB_REPO:$COMMIT"

TRAVIS_TAG="$DOCKERHUB_REPO:travis-$TRAVIS_BUILD_NUMBER"
docker tag $DOCKERHUB_REPO:$COMMIT "$TRAVIS_TAG"
docker tag "$AVALANCHE_IMAGE" "$TRAVIS_TAG"

if [[ $TRAVIS_BRANCH == "master" ]]; then
docker tag "$AVALANCHE_IMAGE" "$DOCKERHUB_REPO:latest"
fi

# don't push to dockerhub if this is not being run on the main public repo
# or if it's a PR from a fork ( => secret vars not set )
Expand All @@ -14,6 +23,6 @@ if [[ $TRAVIS_REPO_SLUG != "ava-labs/avalanchego" || -z "$DOCKER_USERNAME" ]];
fi

echo "$DOCKER_PASS" | docker login --username "$DOCKER_USERNAME" --password-stdin
#docker push "$TRAVIS_TAG"

# following should push all tags
docker push $DOCKERHUB_REPO
13 changes: 0 additions & 13 deletions .ci/run_docker.sh

This file was deleted.

3 changes: 2 additions & 1 deletion .ci/run_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ SCRIPTS_PATH=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
SRC_PATH=$(dirname "${SCRIPTS_PATH}")
# Build the runnable Avalanche docker image
bash "${SRC_PATH}"/scripts/build_image.sh
AVALANCHE_IMAGE=$(docker image ls --format="{{.Repository}}" | head -n 1)
AVALANCHE_IMAGE=$(docker image ls --format="{{.Repository}}:{{.Tag}}" | head -n 1)
echo "Using Avalanche Image: $AVALANCHE_IMAGE"

DOCKER_REPO="avaplatform"

Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
- AVALANCHE_HOME=$GOPATH/src/github.com/$TRAVIS_REPO_SLUG/
- E2E_TEST_HOME=$GOPATH/src/github.com/ava-labs/avalanche-testing/
- COMMIT=${TRAVIS_COMMIT::8}
- DOCKERHUB_REPO=avaplatform/gecko
- DOCKERHUB_REPO=avaplatform/avalanchego
- secure: Ozsv2nUqUVSdiaEovsffCBaGIaJdSGEq6zSNr1af74+zhYu1G5Dw3s0u5Uq42NTFygGVAg2ODh1/PSviAK3P7Dzgi3yMtUBD8kAAISJW3lKr/JavBOIsUnekhZYniAS77vUHwpOi6vQxgjhy/ymYxXTSRyHPys7DwZhZcCMiR6Bk/O7w8JbYo2m31mCaJZWpt9m4SCXVr+lK1prYuCOAME5SwKq3eVHfUGKn7w8f7kLUDv6XPLlAjzOQHKq4AD9DwDQX2wubAOc87a4BCti9suaXNyzRtS3AUQXjZkHy8BHyWPnMOIwOT6sVAYEm65fcOPxlawnkbs8ny7xnJMqj9R0tyq7XmnGoaALeXxOcV1B55TFjyo0P48NTugFrdqtQ+LSOvvVQJV/QBoe+sZwUTus+LP5lWl86EnQPGxjll+vXO2Mces+F48eoj9dfPBbBLRLEaxk54l6+H6JHvAG2QRtRG3beh7XbdFYPnt+LEuYdW3kyCRD24JhCrglJlebCnqAKR7GfAICf7ca5+WJj4Fiyyh/tUt4Ss0E53Mvz6NXFNpJVTEcFc3RFjIp/louK1Y2Uxbyr+LT9hw2bvo6Obz9sl/YZs10rCWZnC0zF2WE01tADD8YShrA70349hmtE2FSJLCg2LTVgmTFbS47Rn4QFcmo5AGHDNl31iwj9gKk=
- secure: Si2xR7IOINZRHtH6DbgxhpOH/oX1XL+DvlutmQVS5ZbjXFmvtqB8CT9uDUAKj38R+sgEmAwOENLJcl7SWZfXDE4EYqlcafh/pcBMjm8O6atWrrwmpZSEiHNba2t+yXBN7z5M/KV777FY43SbOEA+/5Bytcluk3Mxjjl5iFXEWai0RH9jmk7lsHmIyPYsAG9/SRwYgr0uZ3T5872HBD7td7+umiTyWshdT3dOXilYWWflc4eniv/ifp/H6A5k9uXrE50KdtaeDcAl5eAp9mItNd8nLenmaNzDkq6IBTUwy+gmEHctq8YbjmtQhdWtdIXDxPFknpBqKsg7oXgstJt11UVqhDcsnX6Trj1GO8InUykMLRDxWMwlCZfZdAuUvhbrHmbFOWF1ANL5Rl7RzUXSov02WAPvrze/8ZFq2O2f28CVkcWCZy/Vei9EhAwQUyJOug6R/1cSOkcqpovc5yf65dLnpUMb+f4fbMk5Z/YPijJ8VZSFU9ul73re6xcWz9PbxZWqsN2Ubqm6EKRB02gxsLbdl56lHcMl6uawrTUFDoie+alkiqlxP8Ey7Phw43os/lxHq9lQN0bZ2Mkq4LMVc4noa5TQNTNxS/hrAIly7IzZVV0VfiLeHJVT/2BWCUhNqw/jL2lpGTPbH0NqG/wIRAAW9BYDlQKc17vBM9Xvs8g=

Expand All @@ -26,7 +26,6 @@ jobs:
dist: bionic
script:
- ".ci/build_and_test.sh"
- ".ci/run_docker.sh"
- ".ci/run_e2e_tests.sh"
- ".ci/after_success.sh"

Expand Down
2 changes: 1 addition & 1 deletion api/health/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// defaultCheckOpts is a Check whose properties represent a default Check
var defaultCheckOpts = check{
executionPeriod: time.Minute,
executionPeriod: 30 * time.Second,
initialDelay: 10 * time.Second,
}

Expand Down
4 changes: 4 additions & 0 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func (service *Info) GetBlockchainID(_ *http.Request, args *GetBlockchainIDArgs,

// PeersReply are the results from calling Peers
type PeersReply struct {
// Number of elements in [Peers]
NumPeers json.Uint64 `json:"numPeers"`
// Each element is a peer
Peers []network.PeerID `json:"peers"`
}

Expand All @@ -142,6 +145,7 @@ func (service *Info) Peers(_ *http.Request, _ *struct{}, reply *PeersReply) erro
service.log.Info("Info: Peers called")

reply.Peers = service.networking.Peers()
reply.NumPeers = json.Uint64(len(reply.Peers))
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ func (m *manager) buildChain(chainParams ChainParameters) (*chain, error) {

// Allows messages to be routed to the new chain
m.ManagerConfig.Router.AddChain(chain.Handler)

// Register the chain with the timeout manager
m.TimeoutManager.RegisterChain(ctx, consensusParams.Namespace)

// If the X or P Chain panics, do not attempt to recover
if m.CriticalChains.Contains(chainParams.ID) {
go ctx.Log.RecoverAndPanic(chain.Handler.Dispatch)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/AppsFlyer/go-sundheit v0.2.0
github.com/Microsoft/go-winio v0.4.14
github.com/ava-labs/coreth v0.3.4 // indirect
github.com/ava-labs/coreth v0.3.5-rc.1 // indirect
github.com/ava-labs/go-ethereum v1.9.3
github.com/btcsuite/btcutil v1.0.2
github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837
Expand Down
9 changes: 3 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ github.com/aristanetworks/goarista v0.0.0-20200812190859-4cb0e71f3c0e h1:tkEt0le
github.com/aristanetworks/goarista v0.0.0-20200812190859-4cb0e71f3c0e/go.mod h1:QZe5Yh80Hp1b6JxQdpfSEEe8X7hTyTEZSosSrFf/oJE=
github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc=
github.com/ava-labs/avalanche-go v0.8.0-beta/go.mod h1:quYojL1hu0ue2glUT1ng28kADs9R94zGdEvfW0/HRg8=
github.com/ava-labs/avalanchego v0.6.1-rc.1/go.mod h1:TT6uA1BETZpVMR0xiFtE8I5Mv4DULlS+lAL3xuYKnpA=
github.com/ava-labs/avalanchego v0.8.0-beta/go.mod h1:quYojL1hu0ue2glUT1ng28kADs9R94zGdEvfW0/HRg8=
github.com/ava-labs/avalanchego v0.8.3/go.mod h1:6zPzQv7m6vSvdKAwH+lLTga0IMd/0+HLMT5OULrpFcU=
github.com/ava-labs/avalanchego v1.0.2-rc.1/go.mod h1:JAkAaaj0AlCDSnfFHZwfcEPA2Sl+fOwyLJ6veWMjQWE=
github.com/ava-labs/coreth v0.2.14-rc.1/go.mod h1:Zhb60GFIB7G5AnUCks0Jo4Rezx/EovL8o+z51aBF1A8=
github.com/ava-labs/coreth v0.2.15-rc.4/go.mod h1:+sK2XGKCNA48uzeHWe4iBzmiOBYmYvnnzLtOkQeQfkk=
github.com/ava-labs/coreth v0.3.3-rc.7 h1:lVEd0Olg22pNou8SrC6y4UDfvyqF40Yts71jIKuJGWY=
github.com/ava-labs/coreth v0.3.3-rc.7/go.mod h1:d5h8SoFyMOoFqg2gHzYgftZlKgZ1MHKKydjyq2hoABk=
github.com/ava-labs/coreth v0.3.4 h1:D6FHQrIUCezVDAG/c86v7is/hOaS87x9QtEd93z+aEI=
github.com/ava-labs/coreth v0.3.4/go.mod h1:d5h8SoFyMOoFqg2gHzYgftZlKgZ1MHKKydjyq2hoABk=
github.com/ava-labs/gecko v0.6.1-rc.1 h1:BhWmoDGA0Obs5ZbEdpNqw/3rx9ZMPmjcZu1oD+yySLY=
github.com/ava-labs/coreth v0.3.5-rc.1 h1:tshf2PaFBOaeZQTA1+E+s6/mUvz0KLIrkNbwXEjljZk=
github.com/ava-labs/coreth v0.3.5-rc.1/go.mod h1:pSwR4F6WrcLEEnWOJtNbBFlnaXFPSHRel3I366xw/ck=
github.com/ava-labs/gecko v0.6.1-rc.1/go.mod h1:TT6uA1BETZpVMR0xiFtE8I5Mv4DULlS+lAL3xuYKnpA=
github.com/ava-labs/go-ethereum v1.9.3 h1:GmnMZ/dlvVAPFmWBzEpRJX49pUAymPfoASLNRJqR0AY=
github.com/ava-labs/go-ethereum v1.9.3/go.mod h1:a+agc6fXfZFsPZCylA3ry4Y8CLCqLKg3Rc23NXZ9aw8=
Expand Down
29 changes: 13 additions & 16 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,26 @@ func main() {
log.Debug("assertions are enabled. This may slow down execution")
}

// IsNATTraversal() for NoRouter is false.
// Which means we tried to perform a NAT activity but we were not successful.
if Config.AttemptedNATTraversal && !Config.Nat.IsNATTraversal() {
log.Error("UPnP or NAT-PMP router attach failed, you may not be listening publicly," +
" please confirm the settings in your router")
}

mapper := nat.NewPortMapper(log, Config.Nat)
defer mapper.UnmapAllPorts()

// Open staking port
port, err := mapper.Map("TCP", Config.StakingLocalPort, stakingPortName)
if !Config.StakingIP.IsPrivate() {
if err == nil {
// The port was mapped and the ip is on a public network, the node
// should be able to be connected to peers on this public network.
Config.StakingIP.Port = port
} else {
// The port mapping errored, however it is possible the node is
// connected directly to a public network.
log.Warn("NAT traversal has failed. Unless the node is connected directly to a public network, the node will be able to connect to less nodes.")
}
} else {
// The reported IP is private, so this node will not be discoverable.
log.Warn("NAT traversal has failed. The node will be able to connect to less nodes.")
}
// we want for NAT Traversal to have the external port (Config.StakingIP.Port) to connect to our
// internal listening port (Config.InternalStakingPort) which should be the same in most cases.
mapper.Map("TCP", Config.StakingIP.Port, Config.StakingIP.Port, stakingPortName)

// Open the HTTP port iff the HTTP server is not listening on localhost
if Config.HTTPHost != "127.0.0.1" && Config.HTTPHost != "localhost" {
_, _ = mapper.Map("TCP", Config.HTTPPort, httpPortName)
// For NAT Traversal we want to route from the external port (Config.ExternalHTTPPort)
// to our internal port (Config.HTTPPort)
mapper.Map("TCP", Config.HTTPPort, Config.HTTPPort, httpPortName)
}

log.Debug("initializing node state")
Expand Down
76 changes: 58 additions & 18 deletions main/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ var (
filepath.Join("/", "usr", "local", "lib", constants.AppName),
filepath.Join(homeDir, dataDirName, "plugins"),
}

// GitCommit should be optionally set at compile time.
GitCommit string
)

var (
Expand Down Expand Up @@ -133,7 +136,7 @@ func init() {
bootstrapIDs := fs.String("bootstrap-ids", "default", "Comma separated list of bootstrap peer ids to connect to. Example: NodeID-JR4dVmy6ffUGAKCBDkyCbeZbyHQBeDsET,NodeID-8CrVPQZ4VSqgL8zTdvL14G8HqAfrBr4z")

// Staking:
consensusPort := fs.Uint("staking-port", 9651, "Port of the consensus server")
stakingPort := fs.Uint("staking-port", 9651, "Port of the consensus server")
fs.BoolVar(&Config.EnableStaking, "staking-enabled", true, "Enable staking. If enabled, Network TLS is required.")
fs.BoolVar(&Config.EnableP2PTLS, "p2p-tls-enabled", true, "Require TLS to authenticate network communication")
fs.StringVar(&Config.StakingKeyFile, "staking-tls-key-file", defaultStakingKeyPath, "TLS private key for staking")
Expand All @@ -149,8 +152,14 @@ func init() {
networkInitialTimeout := fs.Int64("network-initial-timeout", int64(10*time.Second), "Initial timeout value of the adaptive timeout manager, in nanoseconds.")
networkMinimumTimeout := fs.Int64("network-minimum-timeout", int64(500*time.Millisecond), "Minimum timeout value of the adaptive timeout manager, in nanoseconds.")
networkMaximumTimeout := fs.Int64("network-maximum-timeout", int64(10*time.Second), "Maximum timeout value of the adaptive timeout manager, in nanoseconds.")
fs.Float64Var(&Config.NetworkConfig.TimeoutMultiplier, "network-timeout-multiplier", 1.1, "Multiplier of the timeout after a failed request.")
networkTimeoutReduction := fs.Int64("network-timeout-reduction", int64(time.Millisecond), "Reduction of the timeout after a successful request, in nanoseconds.")
networkTimeoutInc := fs.Int64("network-timeout-increase", 60*int64(time.Millisecond), "Increase of network timeout after a failed request, in nanoseconds.")
networkTimeoutDec := fs.Int64("network-timeout-reduction", 12*int64(time.Millisecond), "Decrease of network timeout after a successful request, in nanoseconds.")

// Benchlist Parameters:
fs.IntVar(&Config.BenchlistConfig.Threshold, "benchlist-fail-threshold", 10, "Number of consecutive failed queries before benchlisting a node.")
fs.BoolVar(&Config.BenchlistConfig.PeerSummaryEnabled, "benchlist-peer-summary-enabled", false, "Enables peer specific query latency metrics.")
benchlistDuration := fs.Int64("benchlist-duration", int64(time.Hour), "Amount of time a peer is benchlisted after surpassing the threshold.")
minimumBenchlistFailingDuration := fs.Int64("benchlist-min-failing-duration", int64(5*time.Minute), "Minimum amount of time messages to a peer must be failing before the peer is benched.")

// Plugins:
fs.StringVar(&Config.PluginDir, "plugin-dir", defaultPluginDirs[0], "Plugin directory for Avalanche VMs")
Expand Down Expand Up @@ -194,19 +203,41 @@ func init() {
ferr := fs.Parse(os.Args[1:])

if *version { // If --version used, print version and exit
networkID, err := constants.NetworkID(*networkName)
if err != nil {
Err = err
return
format := "%s ["
args := []interface{}{
node.Version,
}
networkGeneration := constants.NetworkName(networkID)
if networkID == constants.MainnetID {
fmt.Printf("%s [database=%s, network=%s]\n",
node.Version, dbVersion, networkGeneration)
} else {
fmt.Printf("%s [database=%s, network=testnet/%s]\n",
node.Version, dbVersion, networkGeneration)

{
networkID, err := constants.NetworkID(*networkName)
if err != nil {
Err = err
return
}
networkGeneration := constants.NetworkName(networkID)
if networkID == constants.MainnetID {
format += "network=%s"
} else {
format += "network=testnet/%s"
}
args = append(args, networkGeneration)
}

{
format += ", database=%s"
args = append(args, dbVersion)
}

{
if GitCommit != "" {
format += ", commit=%s"
args = append(args, GitCommit)
}
}

format += "]\n"

fmt.Printf(format, args...)
os.Exit(0)
}

Expand Down Expand Up @@ -247,6 +278,7 @@ func init() {
var ip net.IP
// If public IP is not specified, get it using shell command dig
if *consensusIP == "" {
Config.AttemptedNATTraversal = true
Config.Nat = nat.GetRouter()
ip, err = Config.Nat.ExternalIP()
if err != nil {
Expand All @@ -264,9 +296,8 @@ func init() {

Config.StakingIP = utils.IPDesc{
IP: ip,
Port: uint16(*consensusPort),
Port: uint16(*stakingPort),
}
Config.StakingLocalPort = uint16(*consensusPort)

defaultBootstrapIPs, defaultBootstrapIDs := genesis.SampleBeacons(networkID, 5)

Expand Down Expand Up @@ -424,13 +455,22 @@ func init() {
*networkInitialTimeout > *networkMaximumTimeout {
errs.Add(errors.New("initial timeout should be in the range [minimumTimeout, maximumTimeout]"))
}
if *networkTimeoutReduction < 0 {
if *networkTimeoutDec < 0 {
errs.Add(errors.New("timeout reduction can't be negative"))
}
if *networkTimeoutInc < 0 {
errs.Add(errors.New("timeout increase can't be negative"))
}

Config.NetworkConfig.InitialTimeout = time.Duration(*networkInitialTimeout)
Config.NetworkConfig.MinimumTimeout = time.Duration(*networkMinimumTimeout)
Config.NetworkConfig.MaximumTimeout = time.Duration(*networkMaximumTimeout)
Config.NetworkConfig.TimeoutReduction = time.Duration(*networkTimeoutReduction)
Config.NetworkConfig.TimeoutInc = time.Duration(*networkTimeoutInc)
Config.NetworkConfig.TimeoutDec = time.Duration(*networkTimeoutDec)

Config.BenchlistConfig.Duration = time.Duration(*benchlistDuration)
Config.BenchlistConfig.MinimumFailingDuration = time.Duration(*minimumBenchlistFailingDuration)
Config.BenchlistConfig.MaxPortion = (1.0 - (float64(Config.ConsensusParams.Alpha) / float64(Config.ConsensusParams.K))) / 3.0

if *consensusGossipFrequency < 0 {
errs.Add(errors.New("gossip frequency can't be negative"))
Expand Down
Loading

0 comments on commit f5fdb55

Please sign in to comment.