Skip to content

Commit

Permalink
Merge pull request #399 from ava-labs/dev
Browse files Browse the repository at this point in the history
v0.8.2
  • Loading branch information
StephenButtolph authored Sep 13, 2020
2 parents a789089 + 3c73ab9 commit e91c8db
Show file tree
Hide file tree
Showing 29 changed files with 564 additions and 593 deletions.
2 changes: 1 addition & 1 deletion api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type IsBootstrappedResponse struct {
// IsBootstrapped returns nil and sets [reply.IsBootstrapped] == true iff [args.Chain] exists and is done bootstrapping
// Returns an error if the chain doesn't exist
func (service *Info) IsBootstrapped(_ *http.Request, args *IsBootstrappedArgs, reply *IsBootstrappedResponse) error {
service.log.Info("Info: IsBootstrapped called")
service.log.Info("Info: IsBootstrapped called with chain: %s", args.Chain)
if args.Chain == "" {
return fmt.Errorf("argument 'chain' not given")
}
Expand Down
58 changes: 0 additions & 58 deletions chains/awaiter.go

This file was deleted.

44 changes: 0 additions & 44 deletions chains/awaiter_test.go

This file was deleted.

44 changes: 12 additions & 32 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,6 @@ func (m *manager) buildChain(chainParams ChainParameters) (*chain, error) {
ctx.Log.Error("Chain with ID: %s was shutdown due to a panic", chainParams.ID)
})
}

reqWeight := (3*bootstrapWeight + 3) / 4
if reqWeight == 0 {
if err := chain.Engine.Startup(); err != nil {
chain.Handler.Shutdown()
return nil, fmt.Errorf("failed to start consensus engine: %w", err)
}
} else {
awaiter := NewAwaiter(beacons, reqWeight, func() {
ctx.Lock.Lock()
defer ctx.Lock.Unlock()
if err := chain.Engine.Startup(); err != nil {
chain.Ctx.Log.Error("failed to start consensus engine: %s", err)
chain.Handler.Shutdown()
}
})
go m.Net.RegisterConnector(awaiter)
}

if connector, ok := vm.(validators.Connector); ok {
go m.Net.RegisterConnector(connector)
}
return chain, nil
}

Expand Down Expand Up @@ -439,11 +417,12 @@ func (m *manager) createAvalancheChain(
if err := engine.Initialize(aveng.Config{
Config: avbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Validators: validators,
Beacons: beacons,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
Sender: &sender,
Ctx: ctx,
Validators: validators,
Beacons: beacons,
StartupAlpha: (3*bootstrapWeight + 3) / 4,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
Sender: &sender,
},
VtxBlocked: vtxBlocker,
TxBlocked: txBlocker,
Expand Down Expand Up @@ -519,11 +498,12 @@ func (m *manager) createSnowmanChain(
if err := engine.Initialize(smeng.Config{
Config: smbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Validators: validators,
Beacons: beacons,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
Sender: &sender,
Ctx: ctx,
Validators: validators,
Beacons: beacons,
StartupAlpha: (3*bootstrapWeight + 3) / 4,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
Sender: &sender,
},
Blocked: blocked,
VM: vm,
Expand Down
4 changes: 2 additions & 2 deletions main/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func init() {
fs.BoolVar(&Config.HTTPSEnabled, "http-tls-enabled", false, "Upgrade the HTTP server to HTTPs")
fs.StringVar(&Config.HTTPSKeyFile, "http-tls-key-file", "", "TLS private key file for the HTTPs server")
fs.StringVar(&Config.HTTPSCertFile, "http-tls-cert-file", "", "TLS certificate file for the HTTPs server")
fs.BoolVar(&Config.APIRequireAuthToken, "api-require-auth", false, "Require authorization token to call HTTP APIs")
fs.BoolVar(&Config.APIRequireAuthToken, "api-auth-required", false, "Require authorization token to call HTTP APIs")
fs.StringVar(&Config.APIAuthPassword, "api-auth-password", "", "Password used to create/validate API authorization tokens. Can be changed via API call.")

// Bootstrapping:
Expand Down Expand Up @@ -427,7 +427,7 @@ func init() {
Config.HTTPPort = uint16(*httpPort)
if Config.APIRequireAuthToken {
if Config.APIAuthPassword == "" {
errs.Add(errors.New("api-auth-password must be provided if api-require-auth is true"))
errs.Add(errors.New("api-auth-password must be provided if api-auth-required is true"))
return
}
if !password.SufficientlyStrong(Config.APIAuthPassword, password.OK) {
Expand Down
53 changes: 8 additions & 45 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ type Network interface {
// IP.
Track(ip utils.IPDesc)

// Register a new connector that is called whenever a peer is connected to
// or disconnected from. If the connector returns true, then it will never
// be called again. Thread safety must be managed internally in the network.
// The handler will initially be called with this local node's ID.
RegisterConnector(h validators.Connector)

// Returns the description of the nodes this network is currently connected
// to externally. Thread safety must be managed internally to the network.
Peers() []PeerID
Expand Down Expand Up @@ -138,9 +132,8 @@ type network struct {
connectedIPs map[string]struct{}
retryDelay map[string]time.Duration
// TODO: bound the size of [myIPs] to avoid DoS. LRU caching would be ideal
myIPs map[string]struct{} // set of IPs that resulted in my ID.
peers map[[20]byte]*peer
handlers []validators.Connector
myIPs map[string]struct{} // set of IPs that resulted in my ID.
peers map[[20]byte]*peer
}

// NewDefaultNetwork returns a new Network implementation with the provided
Expand Down Expand Up @@ -288,6 +281,10 @@ func (n *network) GetAcceptedFrontier(validatorIDs ids.ShortSet, chainID ids.ID,
sent = peer.send(msg)
}
if !sent {
n.log.Debug("failed to send GetAcceptedFrontier(%s, %s, %d)",
vID,
chainID,
requestID)
n.executor.Add(func() { n.router.GetAcceptedFrontierFailed(vID, chainID, requestID) })
n.getAcceptedFrontier.numFailed.Inc()
} else {
Expand Down Expand Up @@ -655,24 +652,6 @@ func (n *network) Dispatch() error {
}
}

// RegisterConnector implements the Network interface
func (n *network) RegisterConnector(h validators.Connector) {
n.stateLock.Lock()
defer n.stateLock.Unlock()

if h.Connected(n.id) {
return
}
for _, peer := range n.peers {
if peer.connected {
if h.Connected(peer.id) {
return
}
}
}
n.handlers = append(n.handlers, h)
}

// IPs implements the Network interface
func (n *network) Peers() []PeerID {
n.stateLock.Lock()
Expand Down Expand Up @@ -1039,15 +1018,7 @@ func (n *network) connected(p *peer) {
n.connectedIPs[str] = struct{}{}
}

for i := 0; i < len(n.handlers); {
if n.handlers[i].Connected(p.id) {
newLen := len(n.handlers) - 1
n.handlers[i] = n.handlers[newLen] // remove the current handler
n.handlers = n.handlers[:newLen]
} else {
i++
}
}
n.router.Connected(p.id)
}

// assumes the stateLock is held when called
Expand All @@ -1068,14 +1039,6 @@ func (n *network) disconnected(p *peer) {
}

if p.connected {
for i := 0; i < len(n.handlers); {
if n.handlers[i].Disconnected(p.id) {
newLen := len(n.handlers) - 1
n.handlers[i] = n.handlers[newLen] // remove the current handler
n.handlers = n.handlers[:newLen]
} else {
i++
}
}
n.router.Disconnected(p.id)
}
}
Loading

0 comments on commit e91c8db

Please sign in to comment.