Skip to content
Merged

v1.9.11 #1237

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Release Notes

## [v1.9.11](https://github.com/ava-labs/avalanchego/releases/tag/v1.9.11)

This version is backwards compatible to [v1.9.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0). It is optional, but encouraged. The supported plugin version is `24`.

### Plugins

- Removed error from `logging.NoLog#Write`
- Added logging to the static VM factory usage
- Fixed incorrect error being returned from `subprocess.Bootstrap`

### Ledger

- Added ledger tx parsing support

### MerkleDB

- Added explicit consistency guarantees when committing multiple `merkledb.trieView`s to disk at once
- Removed reliance on premature root calculations for `merkledb.trieView` validity tracking
- Updated `x/merkledb/README.md`

## [v1.9.10](https://github.com/ava-labs/avalanchego/releases/tag/v1.9.10)

This version is backwards compatible to [v1.9.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.9.0). It is optional, but encouraged. The supported plugin version is `24`.
Expand Down
11 changes: 5 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/storage"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/proposervm"
)
Expand Down Expand Up @@ -925,21 +924,21 @@ func getChainAliases(v *viper.Viper) (map[ids.ID][]string, error) {
return getAliases(v, "chain aliases", ChainAliasesContentKey, ChainAliasesFileKey)
}

func getVMManager(v *viper.Viper) (vms.Manager, error) {
func getVMAliaser(v *viper.Viper) (ids.Aliaser, error) {
vmAliases, err := getVMAliases(v)
if err != nil {
return nil, err
}

manager := vms.NewManager()
aliser := ids.NewAliaser()
for vmID, aliases := range vmAliases {
for _, alias := range aliases {
if err := manager.Alias(vmID, alias); err != nil {
if err := aliser.Alias(vmID, alias); err != nil {
return nil, err
}
}
}
return manager, nil
return aliser, nil
}

// getPathFromDirKey reads flag value from viper instance and then checks the folder existence
Expand Down Expand Up @@ -1401,7 +1400,7 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
}

// VM Aliases
nodeConfig.VMManager, err = getVMManager(v)
nodeConfig.VMAliaser, err = getVMAliaser(v)
if err != nil {
return node.Config{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/ava-labs/avalanchego/utils/profiler"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/vms"
)

type IPCConfig struct {
Expand Down Expand Up @@ -186,7 +185,7 @@ type Config struct {
ChainConfigs map[string]chains.ChainConfig `json:"-"`
ChainAliases map[ids.ID][]string `json:"chainAliases"`

VMManager vms.Manager `json:"-"`
VMAliaser ids.Aliaser `json:"-"`

// Halflife to use for the processing requests tracker.
// Larger halflife --> usage metrics change more slowly.
Expand Down
42 changes: 27 additions & 15 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/vms/nftfx"
"github.com/ava-labs/avalanchego/vms/platformvm"
Expand All @@ -94,8 +95,9 @@ var (

// Node is an instance of an Avalanche node.
type Node struct {
Log logging.Logger
LogFactory logging.Factory
Log logging.Logger
VMFactoryLog logging.Logger
LogFactory logging.Factory

// This node's unique ID used when communicating with other nodes
// (in consensus, for example)
Expand Down Expand Up @@ -176,6 +178,8 @@ type Node struct {
MetricsRegisterer *prometheus.Registry
MetricsGatherer metrics.MultiGatherer

VMManager vms.Manager

// VM endpoint registry
VMRegistry registry.VMRegistry

Expand Down Expand Up @@ -627,7 +631,7 @@ func (n *Node) addDefaultVMAliases() error {

for vmID, aliases := range vmAliases {
for _, alias := range aliases {
if err := n.Config.VMManager.Alias(vmID, alias); err != nil {
if err := n.Config.VMAliaser.Alias(vmID, alias); err != nil {
return err
}
}
Expand Down Expand Up @@ -695,7 +699,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
StakingBLSKey: n.Config.StakingSigningKey,
Log: n.Log,
LogFactory: n.LogFactory,
VMManager: n.Config.VMManager,
VMManager: n.VMManager,
DecisionAcceptorGroup: n.DecisionAcceptorGroup,
ConsensusAcceptorGroup: n.ConsensusAcceptorGroup,
DBManager: n.DBManager,
Expand Down Expand Up @@ -755,9 +759,10 @@ func (n *Node) initVMs() error {
}

vmRegisterer := registry.NewVMRegisterer(registry.VMRegistererConfig{
APIServer: n.APIServer,
Log: n.Log,
VMManager: n.Config.VMManager,
APIServer: n.APIServer,
Log: n.Log,
VMFactoryLog: n.VMFactoryLog,
VMManager: n.VMManager,
})

// Register the VMs that Avalanche supports
Expand Down Expand Up @@ -801,9 +806,9 @@ func (n *Node) initVMs() error {
},
}),
vmRegisterer.Register(context.TODO(), constants.EVMID, &coreth.Factory{}),
n.Config.VMManager.RegisterFactory(context.TODO(), secp256k1fx.ID, &secp256k1fx.Factory{}),
n.Config.VMManager.RegisterFactory(context.TODO(), nftfx.ID, &nftfx.Factory{}),
n.Config.VMManager.RegisterFactory(context.TODO(), propertyfx.ID, &propertyfx.Factory{}),
n.VMManager.RegisterFactory(context.TODO(), secp256k1fx.ID, &secp256k1fx.Factory{}),
n.VMManager.RegisterFactory(context.TODO(), nftfx.ID, &nftfx.Factory{}),
n.VMManager.RegisterFactory(context.TODO(), propertyfx.ID, &propertyfx.Factory{}),
)
if errs.Errored() {
return errs.Err
Expand All @@ -816,7 +821,7 @@ func (n *Node) initVMs() error {
n.VMRegistry = registry.NewVMRegistry(registry.VMRegistryConfig{
VMGetter: registry.NewVMGetter(registry.VMGetterConfig{
FileReader: filesystem.NewReader(),
Manager: n.Config.VMManager,
Manager: n.VMManager,
PluginDirectory: n.Config.PluginDir,
CPUTracker: n.resourceManager,
RuntimeTracker: n.runtimeManager,
Expand Down Expand Up @@ -920,7 +925,7 @@ func (n *Node) initAdminAPI() error {
ProfileDir: n.Config.ProfilerConfig.Dir,
LogFactory: n.LogFactory,
NodeConfig: n.Config,
VMManager: n.Config.VMManager,
VMManager: n.VMManager,
VMRegistry: n.VMRegistry,
},
)
Expand Down Expand Up @@ -978,11 +983,11 @@ func (n *Node) initInfoAPI() error {
AddPrimaryNetworkDelegatorFee: n.Config.AddPrimaryNetworkDelegatorFee,
AddSubnetValidatorFee: n.Config.AddSubnetValidatorFee,
AddSubnetDelegatorFee: n.Config.AddSubnetDelegatorFee,
VMManager: n.Config.VMManager,
VMManager: n.VMManager,
},
n.Log,
n.chainManager,
n.Config.VMManager,
n.VMManager,
n.Config.NetworkConfig.MyIPPort,
n.Net,
primaryValidators,
Expand Down Expand Up @@ -1235,12 +1240,19 @@ func (n *Node) Initialize(
zap.Reflect("config", n.Config),
)

var err error
n.VMFactoryLog, err = logFactory.Make("vm-factory")
if err != nil {
return fmt.Errorf("problem creating vm logger: %w", err)
}

n.VMManager = vms.NewManager(n.VMFactoryLog, config.VMAliaser)

if err := n.initBeacons(); err != nil { // Configure the beacons
return fmt.Errorf("problem initializing node beacons: %w", err)
}

// Set up tracer
var err error
n.tracer, err = trace.New(n.Config.TraceConfig)
if err != nil {
return fmt.Errorf("couldn't initialize tracer: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion snow/consensus/snowball/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (u *unaryNode) DecidedPrefix() int {
return u.decidedPrefix
}

//nolint:gofmt,gofmpt,gofumpt,goimports // this comment is formatted as intended
//nolint:gofmt,gofumpt,goimports // this comment is formatted as intended
//
// This is by far the most complicated function in this algorithm.
// The intuition is that this instance represents a series of consecutive unary
Expand Down
22 changes: 22 additions & 0 deletions utils/crypto/keychain/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
// to sign a hash
type Signer interface {
SignHash([]byte) ([]byte, error)
Sign([]byte) ([]byte, error)
Address() ids.ShortID
}

Expand Down Expand Up @@ -120,6 +121,7 @@ func (l *ledgerKeychain) Get(addr ids.ShortID) (Signer, bool) {
}, true
}

// expects to receive a hash of the unsigned tx bytes
func (l *ledgerSigner) SignHash(b []byte) ([]byte, error) {
// Sign using the address with index l.idx on the ledger device. The number
// of returned signatures should be the same length as the provided indices.
Expand All @@ -139,6 +141,26 @@ func (l *ledgerSigner) SignHash(b []byte) ([]byte, error) {
return sigs[0], err
}

// expects to receive the unsigned tx bytes
func (l *ledgerSigner) Sign(b []byte) ([]byte, error) {
// Sign using the address with index l.idx on the ledger device. The number
// of returned signatures should be the same length as the provided indices.
sigs, err := l.ledger.Sign(b, []uint32{l.idx})
if err != nil {
return nil, err
}

if sigsLen := len(sigs); sigsLen != 1 {
return nil, fmt.Errorf(
"%w. expected 1, got %d",
ErrInvalidNumSignatures,
sigsLen,
)
}

return sigs[0], err
}

func (l *ledgerSigner) Address() ids.ShortID {
return l.addr
}
2 changes: 1 addition & 1 deletion utils/crypto/keychain/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ type Ledger interface {
Address(displayHRP string, addressIndex uint32) (ids.ShortID, error)
Addresses(addressIndices []uint32) ([]ids.ShortID, error)
SignHash(hash []byte, addressIndices []uint32) ([][]byte, error)
// TODO: add SignTransaction
Sign(unsignedTxBytes []byte, addressIndices []uint32) ([][]byte, error)
Disconnect() error
}
15 changes: 15 additions & 0 deletions utils/crypto/keychain/mock_ledger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion utils/crypto/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/crypto/keychain"
"github.com/ava-labs/avalanchego/utils/hashing"
"github.com/ava-labs/avalanchego/version"
)

const rootPath = "m/44'/9000'/0'"
const (
rootPath = "m/44'/9000'/0'"
ledgerBufferLimit = 8192
ledgerPathSize = 9
)

var _ keychain.Ledger = (*Ledger)(nil)

Expand Down Expand Up @@ -79,6 +84,35 @@ func (l *Ledger) SignHash(hash []byte, addressIndices []uint32) ([][]byte, error
return responses, nil
}

func (l *Ledger) Sign(txBytes []byte, addressIndices []uint32) ([][]byte, error) {
// will pass to the ledger addressIndices both as signing paths and change paths
numSigningPaths := len(addressIndices)
numChangePaths := len(addressIndices)
if len(txBytes)+(numSigningPaths+numChangePaths)*ledgerPathSize > ledgerBufferLimit {
// There is a limit on the tx length that can be parsed by the ledger
// app. When the tx that is being signed is too large, we sign with hash
// instead.
//
// Ref: https://github.com/ava-labs/avalanche-wallet-sdk/blob/9a71f05e424e06b94eaccf21fd32d7983ed1b040/src/Wallet/Ledger/provider/ZondaxProvider.ts#L68
unsignedHash := hashing.ComputeHash256(txBytes)
return l.SignHash(unsignedHash, addressIndices)
}
strIndices := convertToSigningPaths(addressIndices)
response, err := l.device.Sign(rootPath, strIndices, txBytes, strIndices)
if err != nil {
return nil, fmt.Errorf("%w: unable to sign transaction", err)
}
responses := make([][]byte, len(strIndices))
for i, index := range strIndices {
sig, ok := response.Signature[index]
if !ok {
return nil, fmt.Errorf("missing signature %s", index)
}
responses[i] = sig
}
return responses, nil
}

func (l *Ledger) Version() (*version.Semantic, error) {
resp, err := l.device.GetVersion()
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions utils/logging/test_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package logging

import (
"errors"
"io"

"go.uber.org/zap"
Expand All @@ -14,15 +13,13 @@ var (
// Discard is a mock WriterCloser that drops all writes and close requests
Discard io.WriteCloser = discard{}

errNoLoggerWrite = errors.New("NoLogger can't write")

_ Logger = NoLog{}
)

type NoLog struct{}

func (NoLog) Write([]byte) (int, error) {
return 0, errNoLoggerWrite
func (NoLog) Write(b []byte) (int, error) {
return len(b), nil
}

func (NoLog) Fatal(string, ...zap.Field) {}
Expand Down
3 changes: 2 additions & 1 deletion version/compatibility.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"24": [
"v1.9.10"
"v1.9.10",
"v1.9.11"
],
"23": [
"v1.9.9"
Expand Down
2 changes: 1 addition & 1 deletion version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
Current = &Semantic{
Major: 1,
Minor: 9,
Patch: 10,
Patch: 11,
}
CurrentApp = &Application{
Major: Current.Major,
Expand Down
Loading