Skip to content

Commit

Permalink
[AVAX] Merge Cortina 14 (v1.10.14)
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht authored Mar 7, 2024
2 parents af6c6c7 + 5dcef28 commit 1872d0a
Show file tree
Hide file tree
Showing 192 changed files with 6,408 additions and 3,734 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build + Unit Tests
name: Unit Tests

on:
push:
Expand All @@ -9,6 +9,11 @@ on:
merge_group:
types: [checks_requested]

# Cancel ongoing workflow runs if a new one is started
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
run_build_unit_tests:
name: build_unit_test
Expand All @@ -25,6 +30,4 @@ jobs:
- name: fuzz_test
shell: bash
if: matrix.os == 'ubuntu-22.04' # Only run on Ubuntu 22.04
run: | # Run each fuzz test 15 seconds
cd ${{ github.workspace }}
./scripts/build_fuzz.sh 15
run: ./scripts/build_fuzz.sh 15 # Run each fuzz test 15 seconds
4 changes: 0 additions & 4 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ava-labs/avalanchego/network"
"github.com/ava-labs/avalanchego/network/peer"
"github.com/ava-labs/avalanchego/snow/networking/benchlist"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/ips"
"github.com/ava-labs/avalanchego/utils/json"
Expand All @@ -47,7 +46,6 @@ type Info struct {
networking network.Network
chainManager chains.Manager
vmManager vms.Manager
validators validators.Set
benchlist benchlist.Manager
}

Expand Down Expand Up @@ -78,7 +76,6 @@ func NewService(
vmManager vms.Manager,
myIP ips.DynamicIPPort,
network network.Network,
validators validators.Set,
benchlist benchlist.Manager,
) (http.Handler, error) {
server := rpc.NewServer()
Expand All @@ -93,7 +90,6 @@ func NewService(
vmManager: vmManager,
myIP: myIP,
networking: network,
validators: validators,
benchlist: benchlist,
},
"info",
Expand Down
2 changes: 1 addition & 1 deletion api/keystore/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const (
maxPackerSize = 1 * units.GiB // max size, in bytes, of something being marshalled by Marshal()
maxSliceLength = 256 * 1024
maxSliceLength = linearcodec.DefaultMaxSliceLength

codecVersion = 0
)
Expand Down
47 changes: 21 additions & 26 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ type ChainParameters struct {
// The IDs of the feature extensions this chain is running.
FxIDs []ids.ID
// Invariant: Only used when [ID] is the P-chain ID.
CustomBeacons validators.Set
CustomBeacons validators.Manager
}

type chain struct {
Name string
Context *snow.ConsensusContext
VM common.VM
Handler handler.Handler
Beacons validators.Set
Beacons validators.Manager
}

// ChainConfig is configuration settings for the current execution.
Expand Down Expand Up @@ -531,24 +531,13 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
}
}

var vdrs validators.Set // Validators validating this blockchain
var hasValidators bool
if m.SybilProtectionEnabled {
vdrs, hasValidators = m.Validators.Get(chainParams.SubnetID)
} else { // Sybil protection is disabled. Every peer validates every subnet.
vdrs, hasValidators = m.Validators.Get(constants.PrimaryNetworkID)
}
if !hasValidators {
return nil, fmt.Errorf("couldn't get validator set of subnet with ID %s. The subnet may not exist", chainParams.SubnetID)
}

var chain *chain
switch vm := vm.(type) {
case vertex.LinearizableVMWithEngine:
chain, err = m.createAvalancheChain(
ctx,
chainParams.GenesisData,
vdrs,
m.Validators,
vm,
fxs,
sb,
Expand All @@ -557,15 +546,15 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c
return nil, fmt.Errorf("error while creating new avalanche vm %w", err)
}
case block.ChainVM:
beacons := vdrs
beacons := m.Validators
if chainParams.ID == constants.PlatformChainID {
beacons = chainParams.CustomBeacons
}

chain, err = m.createSnowmanChain(
ctx,
chainParams.GenesisData,
vdrs,
m.Validators,
beacons,
vm,
fxs,
Expand Down Expand Up @@ -594,7 +583,7 @@ func (m *manager) AddRegistrant(r Registrant) {
func (m *manager) createAvalancheChain(
ctx *snow.ConsensusContext,
genesisData []byte,
vdrs validators.Set,
vdrs validators.Manager,
vm vertex.LinearizableVMWithEngine,
fxs []*common.Fx,
sb subnets.Subnet,
Expand Down Expand Up @@ -816,7 +805,10 @@ func (m *manager) createAvalancheChain(
appSender: snowmanMessageSender,
}

bootstrapWeight := vdrs.Weight()
bootstrapWeight, err := vdrs.TotalWeight(ctx.SubnetID)
if err != nil {
return nil, fmt.Errorf("error while fetching weight for subnet %s: %w", ctx.SubnetID, err)
}

consensusParams := sb.Config().ConsensusParameters
sampleK := consensusParams.K
Expand All @@ -828,7 +820,7 @@ func (m *manager) createAvalancheChain(
if err != nil {
return nil, fmt.Errorf("error creating peer tracker: %w", err)
}
vdrs.RegisterCallbackListener(connectedValidators)
vdrs.RegisterCallbackListener(ctx.SubnetID, connectedValidators)

// Asynchronously passes messages from the network to the consensus engine
h, err := handler.New(
Expand All @@ -848,7 +840,7 @@ func (m *manager) createAvalancheChain(

connectedBeacons := tracker.NewPeers()
startupTracker := tracker.NewStartup(connectedBeacons, (3*bootstrapWeight+3)/4)
vdrs.RegisterCallbackListener(startupTracker)
vdrs.RegisterCallbackListener(ctx.SubnetID, startupTracker)

snowmanCommonCfg := common.Config{
Ctx: ctx,
Expand Down Expand Up @@ -998,8 +990,8 @@ func (m *manager) createAvalancheChain(
func (m *manager) createSnowmanChain(
ctx *snow.ConsensusContext,
genesisData []byte,
vdrs validators.Set,
beacons validators.Set,
vdrs validators.Manager,
beacons validators.Manager,
vm block.ChainVM,
fxs []*common.Fx,
sb subnets.Subnet,
Expand Down Expand Up @@ -1164,7 +1156,10 @@ func (m *manager) createSnowmanChain(
return nil, err
}

bootstrapWeight := beacons.Weight()
bootstrapWeight, err := beacons.TotalWeight(ctx.SubnetID)
if err != nil {
return nil, fmt.Errorf("error while fetching weight for subnet %s: %w", ctx.SubnetID, err)
}

consensusParams := sb.Config().ConsensusParameters
sampleK := consensusParams.K
Expand All @@ -1176,7 +1171,7 @@ func (m *manager) createSnowmanChain(
if err != nil {
return nil, fmt.Errorf("error creating peer tracker: %w", err)
}
vdrs.RegisterCallbackListener(connectedValidators)
vdrs.RegisterCallbackListener(ctx.SubnetID, connectedValidators)

// Asynchronously passes messages from the network to the consensus engine
h, err := handler.New(
Expand All @@ -1196,7 +1191,7 @@ func (m *manager) createSnowmanChain(

connectedBeacons := tracker.NewPeers()
startupTracker := tracker.NewStartup(connectedBeacons, (3*bootstrapWeight+3)/4)
beacons.RegisterCallbackListener(startupTracker)
beacons.RegisterCallbackListener(ctx.SubnetID, startupTracker)

commonCfg := common.Config{
Ctx: ctx,
Expand Down Expand Up @@ -1358,7 +1353,7 @@ func (m *manager) registerBootstrappedHealthChecks() error {
if !m.IsBootstrapped(constants.PlatformChainID) {
return "node is currently bootstrapping", nil
}
if !validators.Contains(m.Validators, constants.PrimaryNetworkID, m.NodeID) {
if _, ok := m.Validators.GetValidator(constants.PrimaryNetworkID, m.NodeID); !ok {
return "node is not a primary network validator", nil
}

Expand Down
2 changes: 1 addition & 1 deletion codec/linearcodec/camino_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewCamino(tagNames []string, maxSliceLen uint32) CaminoCodec {

// NewDefault is a convenience constructor; it returns a new codec with reasonable default values
func NewCaminoDefault() CaminoCodec {
return NewCamino([]string{reflectcodec.DefaultTagName}, defaultMaxSliceLength)
return NewCamino([]string{reflectcodec.DefaultTagName}, DefaultMaxSliceLength)
}

// NewCustomMaxLength is a convenience constructor; it returns a new codec with custom max length and default tags
Expand Down
2 changes: 1 addition & 1 deletion codec/linearcodec/camino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVectorsCamino(t *testing.T) {

func TestMultipleTagsCamino(t *testing.T) {
for _, test := range codec.MultipleTagsTests {
c := NewCamino([]string{"tag1", "tag2"}, defaultMaxSliceLength)
c := NewCamino([]string{"tag1", "tag2"}, DefaultMaxSliceLength)
test(c, t)
}
}
Expand Down
4 changes: 2 additions & 2 deletions codec/linearcodec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
// default max length of a slice being marshalled by Marshal(). Should be <= math.MaxUint32.
defaultMaxSliceLength = 256 * 1024
DefaultMaxSliceLength = 256 * 1024
)

var (
Expand Down Expand Up @@ -56,7 +56,7 @@ func New(tagNames []string, maxSliceLen uint32) Codec {

// NewDefault is a convenience constructor; it returns a new codec with reasonable default values
func NewDefault() Codec {
return New([]string{reflectcodec.DefaultTagName}, defaultMaxSliceLength)
return New([]string{reflectcodec.DefaultTagName}, DefaultMaxSliceLength)
}

// NewCustomMaxLength is a convenience constructor; it returns a new codec with custom max length and default tags
Expand Down
2 changes: 1 addition & 1 deletion codec/linearcodec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestVectors(t *testing.T) {

func TestMultipleTags(t *testing.T) {
for _, test := range codec.MultipleTagsTests {
c := New([]string{"tag1", "tag2"}, defaultMaxSliceLength)
c := New([]string{"tag1", "tag2"}, DefaultMaxSliceLength)
test(c, t)
}
}
Expand Down
10 changes: 9 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,20 @@ const (
chainUpgradeFileName = "upgrade"
subnetConfigFileExt = ".json"
ipResolutionTimeout = 30 * time.Second

ipcDeprecationMsg = "IPC API is deprecated"
keystoreDeprecationMsg = "keystore API is deprecated"
)

var (
// Deprecated key --> deprecation message (i.e. which key replaces it)
// TODO: deprecate "BootstrapIDsKey" and "BootstrapIPsKey"
deprecatedKeys = map[string]string{}
deprecatedKeys = map[string]string{
IpcAPIEnabledKey: ipcDeprecationMsg,
IpcsChainIDsKey: ipcDeprecationMsg,
IpcsPathKey: ipcDeprecationMsg,
KeystoreAPIEnabledKey: keystoreDeprecationMsg,
}

errSybilProtectionDisabledStakerWeights = errors.New("sybil protection disabled weights must be positive")
errSybilProtectionDisabledOnPublicNetwork = errors.New("sybil protection disabled on public network")
Expand Down
2 changes: 2 additions & 0 deletions database/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ type Iterator interface {

// Key returns the key of the current key/value pair, or nil if done.
// If the database is closed, must still report the current contents.
// Behavior is undefined after Release is called.
Key() []byte

// Value returns the value of the current key/value pair, or nil if done.
// If the database is closed, must still report the current contents.
// Behavior is undefined after Release is called.
Value() []byte

// Release releases associated resources. Release should always succeed and
Expand Down
Loading

0 comments on commit 1872d0a

Please sign in to comment.