Skip to content

Commit

Permalink
Merge pull request #228 from StephenButtolph/network-upgrade
Browse files Browse the repository at this point in the history
Network upgrade
  • Loading branch information
StephenButtolph authored Jun 8, 2020
2 parents 49730ea + 367b5c3 commit e3aa5e7
Show file tree
Hide file tree
Showing 86 changed files with 3,189 additions and 1,419 deletions.
46 changes: 24 additions & 22 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ava-labs/gecko/api"
"github.com/ava-labs/gecko/chains"
"github.com/ava-labs/gecko/genesis"
"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/network"
"github.com/ava-labs/gecko/snow/engine/common"
Expand Down Expand Up @@ -46,38 +47,45 @@ func NewService(nodeID ids.ShortID, networkID uint32, log logging.Logger, chainM
return &common.HTTPHandler{Handler: newServer}
}

// GetNodeIDArgs are the arguments for calling GetNodeID
type GetNodeIDArgs struct{}

// GetNodeIDReply are the results from calling GetNodeID
type GetNodeIDReply struct {
NodeID ids.ShortID `json:"nodeID"`
}

// GetNodeID returns the node ID of this node
func (service *Admin) GetNodeID(r *http.Request, args *GetNodeIDArgs, reply *GetNodeIDReply) error {
func (service *Admin) GetNodeID(_ *http.Request, _ *struct{}, reply *GetNodeIDReply) error {
service.log.Debug("Admin: GetNodeID called")

reply.NodeID = service.nodeID
return nil
}

// GetNetworkIDArgs are the arguments for calling GetNetworkID
type GetNetworkIDArgs struct{}

// GetNetworkIDReply are the results from calling GetNetworkID
type GetNetworkIDReply struct {
NetworkID cjson.Uint32 `json:"networkID"`
}

// GetNetworkID returns the network ID this node is running on
func (service *Admin) GetNetworkID(r *http.Request, args *GetNetworkIDArgs, reply *GetNetworkIDReply) error {
func (service *Admin) GetNetworkID(_ *http.Request, _ *struct{}, reply *GetNetworkIDReply) error {
service.log.Debug("Admin: GetNetworkID called")

reply.NetworkID = cjson.Uint32(service.networkID)
return nil
}

// GetNetworkNameReply is the result from calling GetNetworkName
type GetNetworkNameReply struct {
NetworkName string `json:"networkName"`
}

// GetNetworkName returns the network name this node is running on
func (service *Admin) GetNetworkName(_ *http.Request, _ *struct{}, reply *GetNetworkNameReply) error {
service.log.Debug("Admin: GetNetworkName called")

reply.NetworkName = genesis.NetworkName(service.networkID)
return nil
}

// GetBlockchainIDArgs are the arguments for calling GetBlockchainID
type GetBlockchainIDArgs struct {
Alias string `json:"alias"`
Expand All @@ -89,24 +97,21 @@ type GetBlockchainIDReply struct {
}

// GetBlockchainID returns the blockchain ID that resolves the alias that was supplied
func (service *Admin) GetBlockchainID(r *http.Request, args *GetBlockchainIDArgs, reply *GetBlockchainIDReply) error {
func (service *Admin) GetBlockchainID(_ *http.Request, args *GetBlockchainIDArgs, reply *GetBlockchainIDReply) error {
service.log.Debug("Admin: GetBlockchainID called")

bID, err := service.chainManager.Lookup(args.Alias)
reply.BlockchainID = bID.String()
return err
}

// PeersArgs are the arguments for calling Peers
type PeersArgs struct{}

// PeersReply are the results from calling Peers
type PeersReply struct {
Peers []network.PeerID `json:"peers"`
}

// Peers returns the list of current validators
func (service *Admin) Peers(r *http.Request, args *PeersArgs, reply *PeersReply) error {
func (service *Admin) Peers(_ *http.Request, _ *struct{}, reply *PeersReply) error {
service.log.Debug("Admin: Peers called")
reply.Peers = service.networking.Peers()
return nil
Expand All @@ -123,22 +128,19 @@ type StartCPUProfilerReply struct {
}

// StartCPUProfiler starts a cpu profile writing to the specified file
func (service *Admin) StartCPUProfiler(r *http.Request, args *StartCPUProfilerArgs, reply *StartCPUProfilerReply) error {
func (service *Admin) StartCPUProfiler(_ *http.Request, args *StartCPUProfilerArgs, reply *StartCPUProfilerReply) error {
service.log.Debug("Admin: StartCPUProfiler called with %s", args.Filename)
reply.Success = true
return service.performance.StartCPUProfiler(args.Filename)
}

// StopCPUProfilerArgs are the arguments for calling StopCPUProfiler
type StopCPUProfilerArgs struct{}

// StopCPUProfilerReply are the results from calling StopCPUProfiler
type StopCPUProfilerReply struct {
Success bool `json:"success"`
}

// StopCPUProfiler stops the cpu profile
func (service *Admin) StopCPUProfiler(r *http.Request, args *StopCPUProfilerArgs, reply *StopCPUProfilerReply) error {
func (service *Admin) StopCPUProfiler(_ *http.Request, _ *struct{}, reply *StopCPUProfilerReply) error {
service.log.Debug("Admin: StopCPUProfiler called")
reply.Success = true
return service.performance.StopCPUProfiler()
Expand All @@ -155,7 +157,7 @@ type MemoryProfileReply struct {
}

// MemoryProfile runs a memory profile writing to the specified file
func (service *Admin) MemoryProfile(r *http.Request, args *MemoryProfileArgs, reply *MemoryProfileReply) error {
func (service *Admin) MemoryProfile(_ *http.Request, args *MemoryProfileArgs, reply *MemoryProfileReply) error {
service.log.Debug("Admin: MemoryProfile called with %s", args.Filename)
reply.Success = true
return service.performance.MemoryProfile(args.Filename)
Expand All @@ -172,7 +174,7 @@ type LockProfileReply struct {
}

// LockProfile runs a mutex profile writing to the specified file
func (service *Admin) LockProfile(r *http.Request, args *LockProfileArgs, reply *LockProfileReply) error {
func (service *Admin) LockProfile(_ *http.Request, args *LockProfileArgs, reply *LockProfileReply) error {
service.log.Debug("Admin: LockProfile called with %s", args.Filename)
reply.Success = true
return service.performance.LockProfile(args.Filename)
Expand All @@ -190,7 +192,7 @@ type AliasReply struct {
}

// Alias attempts to alias an HTTP endpoint to a new name
func (service *Admin) Alias(r *http.Request, args *AliasArgs, reply *AliasReply) error {
func (service *Admin) Alias(_ *http.Request, args *AliasArgs, reply *AliasReply) error {
service.log.Debug("Admin: Alias called with URL: %s, Alias: %s", args.Endpoint, args.Alias)
reply.Success = true
return service.httpServer.AddAliasesWithReadLock(args.Endpoint, args.Alias)
Expand Down Expand Up @@ -233,7 +235,7 @@ type StacktraceReply struct {
}

// Stacktrace returns the current global stacktrace
func (service *Admin) Stacktrace(_ *http.Request, _ *StacktraceArgs, reply *StacktraceReply) error {
func (service *Admin) Stacktrace(_ *http.Request, _ *struct{}, reply *StacktraceReply) error {
reply.Stacktrace = logging.Stacktrace{Global: true}.String()
return nil
}
5 changes: 3 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func (s *Server) RegisterChain(ctx *snow.Context, vmIntf interface{}) {
}

// all subroutes to a chain begin with "bc/<the chain's ID>"
defaultEndpoint := "bc/" + ctx.ChainID.String()
httpLogger, err := s.factory.MakeChain(ctx.ChainID, "http")
chainID := ctx.ChainID.String()
defaultEndpoint := "bc/" + chainID
httpLogger, err := s.factory.MakeChain(chainID, "http")
if err != nil {
s.log.Error("Failed to create new http logger: %s", err)
return
Expand Down
38 changes: 26 additions & 12 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

const (
defaultChannelSize = 1000
requestTimeout = 2 * time.Second
requestTimeout = 4 * time.Second
gossipFrequency = 10 * time.Second
shutdownTimeout = 1 * time.Second
)
Expand Down Expand Up @@ -247,8 +247,13 @@ func (m *manager) ForceCreateChain(chain ChainParameters) {
}
}

primaryAlias, err := m.PrimaryAlias(chain.ID)
if err != nil {
primaryAlias = chain.ID.String()
}

// Create the log and context of the chain
chainLog, err := m.logFactory.MakeChain(chain.ID, "")
chainLog, err := m.logFactory.MakeChain(primaryAlias, "")
if err != nil {
m.log.Error("error while creating chain's log %s", err)
return
Expand All @@ -266,12 +271,9 @@ func (m *manager) ForceCreateChain(chain ChainParameters) {
SharedMemory: m.sharedMemory.NewBlockchainSharedMemory(chain.ID),
BCLookup: m,
}

consensusParams := m.consensusParams
if alias, err := m.PrimaryAlias(ctx.ChainID); err == nil {
consensusParams.Namespace = fmt.Sprintf("gecko_%s", alias)
} else {
consensusParams.Namespace = fmt.Sprintf("gecko_%s", ctx.ChainID)
}
consensusParams.Namespace = fmt.Sprintf("gecko_%s", primaryAlias)

// The validators of this blockchain
var validators validators.Set // Validators validating this blockchain
Expand Down Expand Up @@ -360,8 +362,8 @@ func (m *manager) createAvalancheChain(
db := prefixdb.New(ctx.ChainID.Bytes(), m.db)
vmDB := prefixdb.New([]byte("vm"), db)
vertexDB := prefixdb.New([]byte("vertex"), db)
vertexBootstrappingDB := prefixdb.New([]byte("vertex_bootstrapping"), db)
txBootstrappingDB := prefixdb.New([]byte("tx_bootstrapping"), db)
vertexBootstrappingDB := prefixdb.New([]byte("vertex_bs"), db)
txBootstrappingDB := prefixdb.New([]byte("tx_bs"), db)

vtxBlocker, err := queue.New(vertexBootstrappingDB)
if err != nil {
Expand Down Expand Up @@ -429,7 +431,13 @@ func (m *manager) createAvalancheChain(

// Asynchronously passes messages from the network to the consensus engine
handler := &router.Handler{}
handler.Initialize(&engine, msgChan, defaultChannelSize)
handler.Initialize(
&engine,
msgChan,
defaultChannelSize,
fmt.Sprintf("%s_handler", consensusParams.Namespace),
consensusParams.Metrics,
)

// Allows messages to be routed to the new chain
m.chainRouter.AddChain(handler)
Expand Down Expand Up @@ -465,7 +473,7 @@ func (m *manager) createSnowmanChain(

db := prefixdb.New(ctx.ChainID.Bytes(), m.db)
vmDB := prefixdb.New([]byte("vm"), db)
bootstrappingDB := prefixdb.New([]byte("bootstrapping"), db)
bootstrappingDB := prefixdb.New([]byte("bs"), db)

blocked, err := queue.New(bootstrappingDB)
if err != nil {
Expand Down Expand Up @@ -515,7 +523,13 @@ func (m *manager) createSnowmanChain(

// Asynchronously passes messages from the network to the consensus engine
handler := &router.Handler{}
handler.Initialize(&engine, msgChan, defaultChannelSize)
handler.Initialize(
&engine,
msgChan,
defaultChannelSize,
fmt.Sprintf("%s_handler", consensusParams.Namespace),
consensusParams.Metrics,
)

// Allow incoming messages to be routed to the new chain
m.chainRouter.AddChain(handler)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AppsFlyer/go-sundheit v0.2.0
github.com/allegro/bigcache v1.2.1 // indirect
github.com/aristanetworks/goarista v0.0.0-20200520141224-0f14e646773f // indirect
github.com/ava-labs/coreth v0.2.0 // Added manually; don't delete
github.com/ava-labs/coreth v0.2.4 // Added manually; don't delete
github.com/ava-labs/go-ethereum v1.9.3 // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1 v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/aristanetworks/glog v0.0.0-20191112221043-67e8567f59f3/go.mod h1:KASm
github.com/aristanetworks/goarista v0.0.0-20200520141224-0f14e646773f h1:uM6lu1fpmCwf54zb6Ckkvphioq8MLlyFb/TlTgPpCKc=
github.com/aristanetworks/goarista v0.0.0-20200520141224-0f14e646773f/go.mod h1:QZe5Yh80Hp1b6JxQdpfSEEe8X7hTyTEZSosSrFf/oJE=
github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc=
github.com/ava-labs/coreth v0.2.0 h1:HjR4RMTnWvXhXlnEbFNGF5pbcxfemVxZeEzC4BTIrIw=
github.com/ava-labs/coreth v0.2.0/go.mod h1:pGolKipwq5vGIY2IBBcBkMYrqniXMsS5SBn+BBi4+Js=
github.com/ava-labs/coreth v0.2.4 h1:MhnbuRyMcij7WU4+frayp40quc44AMPc4IrxXhmucWw=
github.com/ava-labs/coreth v0.2.4/go.mod h1:pGolKipwq5vGIY2IBBcBkMYrqniXMsS5SBn+BBi4+Js=
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=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
3 changes: 3 additions & 0 deletions ids/unique_bag.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (b *UniqueBag) Difference(diff *UniqueBag) {
// GetSet ...
func (b *UniqueBag) GetSet(id ID) BitSet { return (*b)[*id.ID] }

// RemoveSet ...
func (b *UniqueBag) RemoveSet(id ID) { delete(*b, id.Key()) }

// List ...
func (b *UniqueBag) List() []ID {
idList := []ID(nil)
Expand Down
6 changes: 3 additions & 3 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
defer Config.DB.Close()

if Config.StakingIP.IsZero() {
log.Warn("NAT traversal has failed. If this node becomes a staker, it may lose its reward due to being unreachable.")
log.Warn("NAT traversal has failed. It will be able to connect to less nodes.")
}

// Track if sybil control is enforced
Expand All @@ -62,7 +62,7 @@ func main() {

// Track if assertions should be executed
if Config.LoggingConfig.Assertions {
log.Warn("assertions are enabled. This may slow down execution")
log.Debug("assertions are enabled. This may slow down execution")
}

mapper := nat.NewDefaultMapper(log, Config.Nat, nat.TCP, "gecko")
Expand All @@ -83,5 +83,5 @@ func main() {

log.Debug("dispatching node handlers")
err = node.Dispatch()
log.Debug("dispatch returned with: %s", err)
log.Debug("node dispatching returned with %s", err)
}
Loading

0 comments on commit e3aa5e7

Please sign in to comment.