Skip to content

Commit

Permalink
Merge branch 'remove-block-lookup-2' into remove-status-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jun 25, 2024
2 parents d3c8424 + ae07a68 commit e71dce7
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 205 deletions.
1 change: 1 addition & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func deprecateFlags(fs *pflag.FlagSet) error {
func addProcessFlags(fs *pflag.FlagSet) {
// If true, print the version and quit.
fs.Bool(VersionKey, false, "If true, print version and quit")
fs.Bool(VersionJSONKey, false, "If true, print version in JSON format and quit")
}

func addNodeFlags(fs *pflag.FlagSet) {
Expand Down
1 change: 1 addition & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
ConfigContentKey = "config-file-content"
ConfigContentTypeKey = "config-file-content-type"
VersionKey = "version"
VersionJSONKey = "version-json"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
NetworkNameKey = "network-id"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ require (
gonum.org/v1/gonum v0.11.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.2
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -108,7 +108,7 @@ require (
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand Down Expand Up @@ -1027,8 +1027,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
19 changes: 18 additions & 1 deletion main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -29,8 +30,24 @@ func main() {
os.Exit(1)
}

if v.GetBool(config.VersionJSONKey) && v.GetBool(config.VersionKey) {
fmt.Println("can't print both JSON and human readable versions")
os.Exit(1)
}

if v.GetBool(config.VersionJSONKey) {
versions := version.GetVersions()
jsonBytes, err := json.MarshalIndent(versions, "", " ")
if err != nil {
fmt.Printf("couldn't marshal versions: %s\n", err)
os.Exit(1)
}
fmt.Println(string(jsonBytes))
os.Exit(0)
}

if v.GetBool(config.VersionKey) {
fmt.Print(version.String)
fmt.Println(version.GetVersions().String())
os.Exit(0)
}

Expand Down
2 changes: 1 addition & 1 deletion snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func (t *Transitive) buildBlocks(ctx context.Context) error {

// TODO: Technically this may incorrectly log a warning if the block
// that was just built caused votes to be applied such that the block
// was rejected or was accepted along with one of it's children. This
// was rejected or was accepted along with one of its children. This
// should be cleaned up to never produce an invalid warning.
if t.canIssueChildOn(blk.ID()) {
t.Ctx.Log.Verbo("successfully issued new block from the VM")
Expand Down
53 changes: 41 additions & 12 deletions tests/e2e/vms/xsvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/subnet"
Expand All @@ -35,9 +36,17 @@ func XSVMSubnetsOrPanic(nodes ...*tmpnet.Node) []*tmpnet.Subnet {
if err != nil {
panic(err)
}
subnetANodes := nodes
subnetBNodes := nodes
if len(nodes) > 1 {
// Validate tmpnet bootstrap of a disjoint validator set
midpoint := len(nodes) / 2
subnetANodes = nodes[:midpoint]
subnetBNodes = nodes[midpoint:]
}
return []*tmpnet.Subnet{
subnet.NewXSVMOrPanic(subnetAName, key, nodes...),
subnet.NewXSVMOrPanic(subnetBName, key, nodes...),
subnet.NewXSVMOrPanic(subnetAName, key, subnetANodes...),
subnet.NewXSVMOrPanic(subnetBName, key, subnetBNodes...),
}
}

Expand All @@ -55,14 +64,21 @@ var _ = ginkgo.Describe("[XSVM]", func() {
sourceChain := sourceSubnet.Chains[0]
destinationChain := destinationSubnet.Chains[0]

apiNode := network.Nodes[0]
tests.Outf(" issuing transactions on %s (%s)\n", apiNode.NodeID, apiNode.URI)
sourceValidators := getNodesForIDs(network.Nodes, sourceSubnet.ValidatorIDs)
require.NotEmpty(sourceValidators)
sourceAPINode := sourceValidators[0]
tests.Outf(" issuing transactions for source subnet on %s (%s)\n", sourceAPINode.NodeID, sourceAPINode.URI)

destinationValidators := getNodesForIDs(network.Nodes, destinationSubnet.ValidatorIDs)
require.NotEmpty(destinationValidators)
destinationAPINode := destinationValidators[0]
tests.Outf(" issuing transactions for destination subnet on %s (%s)\n", destinationAPINode.NodeID, destinationAPINode.URI)

destinationKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

ginkgo.By("checking that the funded key has sufficient funds for the export")
sourceClient := api.NewClient(apiNode.URI, sourceChain.ChainID.String())
sourceClient := api.NewClient(sourceAPINode.URI, sourceChain.ChainID.String())
initialSourcedBalance, err := sourceClient.Balance(
e2e.DefaultContext(),
sourceChain.PreFundedKey.Address(),
Expand All @@ -75,7 +91,7 @@ var _ = ginkgo.Describe("[XSVM]", func() {
exportTxStatus, err := export.Export(
e2e.DefaultContext(),
&export.Config{
URI: apiNode.URI,
URI: sourceAPINode.URI,
SourceChainID: sourceChain.ChainID,
DestinationChainID: destinationChain.ChainID,
Amount: units.Schmeckle,
Expand All @@ -87,7 +103,7 @@ var _ = ginkgo.Describe("[XSVM]", func() {
tests.Outf(" issued transaction with ID: %s\n", exportTxStatus.TxID)

ginkgo.By("checking that the export transaction has been accepted on all nodes")
for _, node := range network.Nodes[1:] {
for _, node := range sourceValidators[1:] {
require.NoError(api.AwaitTxAccepted(
e2e.DefaultContext(),
api.NewClient(node.URI, sourceChain.ChainID.String()),
Expand All @@ -104,7 +120,7 @@ var _ = ginkgo.Describe("[XSVM]", func() {
transferTxStatus, err := transfer.Transfer(
e2e.DefaultContext(),
&transfer.Config{
URI: apiNode.URI,
URI: destinationAPINode.URI,
ChainID: destinationChain.ChainID,
AssetID: destinationChain.ChainID,
Amount: units.Schmeckle,
Expand All @@ -116,14 +132,14 @@ var _ = ginkgo.Describe("[XSVM]", func() {
tests.Outf(" issued transaction with ID: %s\n", transferTxStatus.TxID)

ginkgo.By(fmt.Sprintf("importing to blockchain %s on subnet %s", destinationChain.ChainID, destinationSubnet.SubnetID))
sourceURIs := make([]string, len(network.Nodes))
for i, node := range network.Nodes {
sourceURIs := make([]string, len(sourceValidators))
for i, node := range sourceValidators {
sourceURIs[i] = node.URI
}
importTxStatus, err := importtx.Import(
e2e.DefaultContext(),
&importtx.Config{
URI: apiNode.URI,
URI: destinationAPINode.URI,
SourceURIs: sourceURIs,
SourceChainID: sourceChain.ChainID.String(),
DestinationChainID: destinationChain.ChainID.String(),
Expand All @@ -140,9 +156,22 @@ var _ = ginkgo.Describe("[XSVM]", func() {
require.GreaterOrEqual(initialSourcedBalance-units.Schmeckle, sourceBalance)

ginkgo.By("checking that the balance of the destination key is non-zero")
destinationClient := api.NewClient(apiNode.URI, destinationChain.ChainID.String())
destinationClient := api.NewClient(destinationAPINode.URI, destinationChain.ChainID.String())
destinationBalance, err := destinationClient.Balance(e2e.DefaultContext(), destinationKey.Address(), sourceChain.ChainID)
require.NoError(err)
require.Equal(units.Schmeckle, destinationBalance)
})
})

// Retrieve the nodes corresponding to the provided IDs
func getNodesForIDs(nodes []*tmpnet.Node, nodeIDs []ids.NodeID) []*tmpnet.Node {
desiredNodes := make([]*tmpnet.Node, 0, len(nodeIDs))
for _, node := range nodes {
for _, nodeID := range nodeIDs {
if node.NodeID == nodeID {
desiredNodes = append(desiredNodes, node)
}
}
}
return desiredNodes
}
6 changes: 3 additions & 3 deletions tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (n *Network) Bootstrap(ctx context.Context, w io.Writer) error {
}

// Don't restart the node during subnet creation since it will always be restarted afterwards.
if err := n.CreateSubnets(ctx, w, false /* restartRequired */); err != nil {
if err := n.CreateSubnets(ctx, w, bootstrapNode.URI, false /* restartRequired */); err != nil {
return err
}

Expand Down Expand Up @@ -646,7 +646,7 @@ func (n *Network) GetSubnet(name string) *Subnet {

// Ensure that each subnet on the network is created. If restartRequired is false, node restart
// to pick up configuration changes becomes the responsibility of the caller.
func (n *Network) CreateSubnets(ctx context.Context, w io.Writer, restartRequired bool) error {
func (n *Network) CreateSubnets(ctx context.Context, w io.Writer, apiURI string, restartRequired bool) error {
createdSubnets := make([]*Subnet, 0, len(n.Subnets))
for _, subnet := range n.Subnets {
if len(subnet.ValidatorIDs) == 0 {
Expand Down Expand Up @@ -748,7 +748,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer, restartRequire
validatorNodes = append(validatorNodes, node)
}

if err := subnet.AddValidators(ctx, w, validatorNodes...); err != nil {
if err := subnet.AddValidators(ctx, w, apiURI, validatorNodes...); err != nil {
return err
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ func (s *Subnet) CreateChains(ctx context.Context, w io.Writer, uri string) erro
}

// Add validators to the subnet
func (s *Subnet) AddValidators(ctx context.Context, w io.Writer, nodes ...*Node) error {
apiURI := nodes[0].URI

func (s *Subnet) AddValidators(ctx context.Context, w io.Writer, apiURI string, nodes ...*Node) error {
wallet, err := s.GetWallet(ctx, apiURI)
if err != nil {
return err
Expand Down
53 changes: 29 additions & 24 deletions version/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ import (
"strings"
)

var (
// String is displayed when CLI arg --version is used
String string
// GitCommit is set in the build script at compile time
var GitCommit string

// GitCommit is set in the build script at compile time
GitCommit string
)
// Versions contains the versions relevant to a build of avalanchego. In
// addition to supporting construction of the string displayed by
// --version, it is used to produce the output of --version-json and can
// be used to unmarshal that output.
type Versions struct {
Application string `json:"application"`
Database string `json:"database"`
RPCChainVM uint64 `json:"rpcchainvm"`
// Commit may be empty if GitCommit was not set at compile time
Commit string `json:"commit"`
Go string `json:"go"`
}

func init() {
format := "%s [database=%s, rpcchainvm=%d"
args := []interface{}{
CurrentApp,
CurrentDatabase,
RPCChainVMProtocol,
}
if GitCommit != "" {
format += ", commit=%s"
args = append(args, GitCommit)
func GetVersions() *Versions {
return &Versions{
Application: CurrentApp.String(),
Database: CurrentDatabase.String(),
RPCChainVM: uint64(RPCChainVMProtocol),
Commit: GitCommit,
Go: strings.TrimPrefix(runtime.Version(), "go"),
}
}

// add golang version
goVersion := runtime.Version()
goVersionNumber := strings.TrimPrefix(goVersion, "go")
format += ", go=%s"
args = append(args, goVersionNumber)

format += "]\n"
String = fmt.Sprintf(format, args...)
func (v *Versions) String() string {
// This format maintains consistency with previous --version output
versionString := fmt.Sprintf("%s [database=%s, rpcchainvm=%d, ", v.Application, v.Database, v.RPCChainVM)
if len(v.Commit) > 0 {
versionString += fmt.Sprintf("commit=%s, ", v.Commit)
}
return versionString + fmt.Sprintf("go=%s]", v.Go)
}
23 changes: 23 additions & 0 deletions version/string_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package version

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestVersionsGetString(t *testing.T) {
versions := Versions{
Application: "1",
Database: "2",
RPCChainVM: 3,
Commit: "4",
Go: "5",
}
require.Equal(t, "1 [database=2, rpcchainvm=3, commit=4, go=5]", versions.String())
versions.Commit = ""
require.Equal(t, "1 [database=2, rpcchainvm=3, go=5]", versions.String())
}
4 changes: 2 additions & 2 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *builder) durationToSleep() (time.Duration, error) {
return 0, fmt.Errorf("%w: %s", errMissingPreferredState, preferredID)
}

nextStakerChangeTime, err := txexecutor.GetNextStakerChangeTime(preferredState)
nextStakerChangeTime, err := state.GetNextStakerChangeTime(preferredState)
if err != nil {
return 0, fmt.Errorf("%w of %s: %w", errCalculatingNextStakerTime, preferredID, err)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (b *builder) BuildBlock(context.Context) (snowman.Block, error) {
return nil, fmt.Errorf("%w: %s", state.ErrMissingParentState, preferredID)
}

timestamp, timeWasCapped, err := txexecutor.NextBlockTime(preferredState, b.txExecutorBackend.Clk)
timestamp, timeWasCapped, err := state.NextBlockTime(preferredState, b.txExecutorBackend.Clk)
if err != nil {
return nil, fmt.Errorf("could not calculate next staker change time: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
return err
}

nextBlkTime, _, err := executor.NextBlockTime(stateDiff, m.txExecutorBackend.Clk)
nextBlkTime, _, err := state.NextBlockTime(stateDiff, m.txExecutorBackend.Clk)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ func TestAddValidatorProposalBlock(t *testing.T) {

// Advance time until next staker change time is [validatorEndTime]
for {
nextStakerChangeTime, err := executor.GetNextStakerChangeTime(env.state)
nextStakerChangeTime, err := state.GetNextStakerChangeTime(env.state)
require.NoError(err)
if nextStakerChangeTime.Equal(validatorEndTime) {
break
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (v *verifier) banffNonOptionBlock(b block.BanffBlock) error {
)
}

nextStakerChangeTime, err := executor.GetNextStakerChangeTime(parentState)
nextStakerChangeTime, err := state.GetNextStakerChangeTime(parentState)
if err != nil {
return fmt.Errorf("could not verify block timestamp: %w", err)
}
Expand Down
Loading

0 comments on commit e71dce7

Please sign in to comment.