Skip to content

Commit

Permalink
Merge branch 'master' into antithesis-image-build-reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored Jul 23, 2024
2 parents 9cd5744 + f4d8a3c commit 00230cd
Show file tree
Hide file tree
Showing 66 changed files with 1,244 additions and 192 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/trigger-antithesis-avalanchego.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
config_image: antithesis-avalanchego-config:${{ github.event.inputs.image_tag || 'latest' }}
images: antithesis-avalanchego-workload:${{ github.event.inputs.image_tag || 'latest' }};antithesis-avalanchego-node:${{ github.event.inputs.image_tag || 'latest' }}
email_recipients: ${{ github.event.inputs.recipients || secrets.ANTITHESIS_RECIPIENTS }}
# Duration is in hours
additional_parameters: |-
custom.duration=${{ github.event.inputs.duration || '11.25' }} # Duration is in hours
custom.duration=${{ github.event.inputs.duration || '11.25' }}
custom.workload=avalanchego
3 changes: 2 additions & 1 deletion .github/workflows/trigger-antithesis-xsvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
config_image: antithesis-xsvm-config:${{ github.event.inputs.image_tag || 'latest' }}
images: antithesis-xsvm-workload:${{ github.event.inputs.image_tag || 'latest' }};antithesis-xsvm-node:${{ github.event.inputs.image_tag || 'latest' }}
email_recipients: ${{ github.event.inputs.recipients || secrets.ANTITHESIS_RECIPIENTS }}
# Duration is in hours
additional_parameters: |-
custom.duration=${{ github.event.inputs.duration || '11.25' }} # Duration is in hours
custom.duration=${{ github.event.inputs.duration || '11.25' }}
custom.workload=xsvm
2 changes: 1 addition & 1 deletion config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ according to its router.

#### `--public-ip` (string)

If this argument is provided, the node assume this is its public IP.
If this argument is provided, the node assumes this is its public IP.

:::tip
When running a local network it may be easiest to set this value to `127.0.0.1`.
Expand Down
6 changes: 3 additions & 3 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the file LICENSE for licensing terms.

// For ease of implementation, our database's interface matches Ethereum's
// database implementation. This was to allow use to use Geth code as is for the
// database implementation. This was to allow us to use Geth code as is for the
// EVM chain.

package database
Expand Down Expand Up @@ -49,13 +49,13 @@ type KeyValueDeleter interface {
Delete(key []byte) error
}

// KeyValueReaderWriter allows read/write acccess to a backing data store.
// KeyValueReaderWriter allows read/write access to a backing data store.
type KeyValueReaderWriter interface {
KeyValueReader
KeyValueWriter
}

// KeyValueWriterDeleter allows write/delete acccess to a backing data store.
// KeyValueWriterDeleter allows write/delete access to a backing data store.
type KeyValueWriterDeleter interface {
KeyValueWriter
KeyValueDeleter
Expand Down
4 changes: 2 additions & 2 deletions genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func (c Config) Unparse() (UnparsedConfig, error) {
func (c *Config) InitialSupply() (uint64, error) {
initialSupply := uint64(0)
for _, allocation := range c.Allocations {
newInitialSupply, err := math.Add64(initialSupply, allocation.InitialAmount)
newInitialSupply, err := math.Add(initialSupply, allocation.InitialAmount)
if err != nil {
return 0, err
}
for _, unlock := range allocation.UnlockSchedule {
newInitialSupply, err = math.Add64(newInitialSupply, unlock.Amount)
newInitialSupply, err = math.Add(newInitialSupply, unlock.Amount)
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/holiman/uint256 v1.2.4
github.com/huin/goupnp v1.3.0
github.com/jackpal/gateway v1.0.6
github.com/jackpal/go-nat-pmp v1.0.2
Expand Down Expand Up @@ -117,7 +118,6 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion snow/consensus/snowball/unary_snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type unarySnowflake struct {
// The corresponding beta values give the threshold required to finalize this instance.
terminationConditions []terminationCondition

// confidence is the number of consecutive succcessful polls for a given
// confidence is the number of consecutive successful polls for a given
// alphaConfidence threshold.
// This instance finalizes when confidence[i] >= terminationConditions[i].beta for any i
confidence []int
Expand Down
4 changes: 2 additions & 2 deletions snow/consensus/snowman/bootstrapper/majority.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (m *Majority) RecordOpinion(_ context.Context, nodeID ids.NodeID, blkIDs se

weight := m.nodeWeights[nodeID]
for blkID := range blkIDs {
newWeight, err := math.Add64(m.received[blkID], weight)
newWeight, err := math.Add(m.received[blkID], weight)
if err != nil {
return err
}
Expand All @@ -84,7 +84,7 @@ func (m *Majority) RecordOpinion(_ context.Context, nodeID ids.NodeID, blkIDs se
err error
)
for _, weight := range m.nodeWeights {
totalWeight, err = math.Add64(totalWeight, weight)
totalWeight, err = math.Add(totalWeight, weight)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion snow/consensus/snowman/bootstrapper/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Sample[T comparable](elements map[T]uint64, maxSize int) (set.Set[T], error
for key, weight := range elements {
keys[i] = key
weights[i] = weight
totalWeight, err = math.Add64(totalWeight, weight)
totalWeight, err = math.Add(totalWeight, weight)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/avalanche/bootstrap/queue/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (jm *JobsWithMissing) cleanRunnableStack(ctx context.Context) error {

job, err := jm.state.GetJob(ctx, jobID)
if err != nil {
return fmt.Errorf("failed to retrieve job on runnnable stack due to: %w", err)
return fmt.Errorf("failed to retrieve job on runnable stack due to: %w", err)
}
deps, err := job.MissingDependencies(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/avalanche/state/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *Serializer) BuildStopVtx(
return nil, err
}
parentHeight := parent.v.vtx.Height()
childHeight, err := math.Add64(parentHeight, 1)
childHeight, err := math.Add(parentHeight, 1)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/snowman/syncer/state_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (ss *stateSyncer) AcceptedStateSummary(ctx context.Context, nodeID ids.Node
continue
}

newWeight, err := safemath.Add64(nodeWeight, ws.weight)
newWeight, err := safemath.Add(nodeWeight, ws.weight)
if err != nil {
ss.Ctx.Log.Error("failed to calculate new summary weight",
zap.Stringer("nodeID", nodeID),
Expand Down
4 changes: 2 additions & 2 deletions snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (t *Transitive) Gossip(ctx context.Context) error {
return nil
}

nextHeightToAccept, err := math.Add64(lastAcceptedHeight, 1)
nextHeightToAccept, err := math.Add(lastAcceptedHeight, 1)
if err != nil {
t.Ctx.Log.Error("skipping block gossip",
zap.String("reason", "block height overflow"),
Expand Down Expand Up @@ -886,7 +886,7 @@ func (t *Transitive) sendQuery(
}

_, lastAcceptedHeight := t.Consensus.LastAccepted()
nextHeightToAccept, err := math.Add64(lastAcceptedHeight, 1)
nextHeightToAccept, err := math.Add(lastAcceptedHeight, 1)
if err != nil {
t.Ctx.Log.Error("dropped query for block",
zap.String("reason", "block height overflow"),
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/benchlist/benchlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (b *benchlist) bench(nodeID ids.NodeID) {
return
}

newBenchedStake, err := safemath.Add64(benchedStake, validatorStake)
newBenchedStake, err := safemath.Add(benchedStake, validatorStake)
if err != nil {
// This should never happen
b.ctx.Log.Error("overflow calculating new benched stake",
Expand Down
4 changes: 2 additions & 2 deletions snow/validators/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *vdrSet) addWeight(nodeID ids.NodeID, weight uint64) error {
}

oldWeight := vdr.Weight
newWeight, err := math.Add64(oldWeight, weight)
newWeight, err := math.Add(oldWeight, weight)
if err != nil {
return err
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (s *vdrSet) subsetWeight(subset set.Set[ids.NodeID]) (uint64, error) {
err error
)
for nodeID := range subset {
totalWeight, err = math.Add64(totalWeight, s.getWeight(nodeID))
totalWeight, err = math.Add(totalWeight, s.getWeight(nodeID))
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $ AVAWL_URIS=... CHAIN_IDS="2S9ypz...AzMj9" go run ./tests/antithesis/xsvm
### Running a workload with docker-compose

Running the test script for a given test setup with the `DEBUG` flag
set will avoid cleaning up the the temporary directory where the
set will avoid cleaning up the temporary directory where the
docker-compose setup is written to. This will allow manual invocation of
docker-compose to see the log output of the workload.

Expand Down
36 changes: 18 additions & 18 deletions utils/math/safe_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ package math

import (
"errors"
"math"

"golang.org/x/exp/constraints"

"github.com/ava-labs/avalanchego/utils"
)

var (
ErrOverflow = errors.New("overflow")
ErrUnderflow = errors.New("underflow")

// Deprecated: Add64 is deprecated. Use Add[uint64] instead.
Add64 = Add[uint64]

// Deprecated: Mul64 is deprecated. Use Mul[uint64] instead.
Mul64 = Mul[uint64]
)

// Add64 returns:
// MaxUint returns the maximum value of an unsigned integer of type T.
func MaxUint[T constraints.Unsigned]() T {
return ^T(0)
}

// Add returns:
// 1) a + b
// 2) If there is overflow, an error
//
// Note that we don't have a generic Add function because checking for
// an overflow requires knowing the max size of a given type, which we
// don't know if we're adding generic types.
func Add64(a, b uint64) (uint64, error) {
if a > math.MaxUint64-b {
func Add[T constraints.Unsigned](a, b T) (T, error) {
if a > MaxUint[T]()-b {
return 0, ErrOverflow
}
return a + b, nil
Expand All @@ -36,20 +40,16 @@ func Add64(a, b uint64) (uint64, error) {
// 2) If there is underflow, an error
func Sub[T constraints.Unsigned](a, b T) (T, error) {
if a < b {
return utils.Zero[T](), ErrUnderflow
return 0, ErrUnderflow
}
return a - b, nil
}

// Mul64 returns:
// Mul returns:
// 1) a * b
// 2) If there is overflow, an error
//
// Note that we don't have a generic Mul function because checking for
// an overflow requires knowing the max size of a given type, which we
// don't know if we're adding generic types.
func Mul64(a, b uint64) (uint64, error) {
if b != 0 && a > math.MaxUint64/b {
func Mul[T constraints.Unsigned](a, b T) (T, error) {
if b != 0 && a > MaxUint[T]()/b {
return 0, ErrOverflow
}
return a * b, nil
Expand Down
41 changes: 26 additions & 15 deletions utils/math/safe_math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,39 @@ import (

const maxUint64 uint64 = math.MaxUint64

func TestAdd64(t *testing.T) {
func TestMaxUint(t *testing.T) {
require := require.New(t)

sum, err := Add64(0, maxUint64)
require.Equal(uint(math.MaxUint), MaxUint[uint]())
require.Equal(uint8(math.MaxUint8), MaxUint[uint8]())
require.Equal(uint16(math.MaxUint16), MaxUint[uint16]())
require.Equal(uint32(math.MaxUint32), MaxUint[uint32]())
require.Equal(uint64(math.MaxUint64), MaxUint[uint64]())
require.Equal(uintptr(math.MaxUint), MaxUint[uintptr]())
}

func TestAdd(t *testing.T) {
require := require.New(t)

sum, err := Add(0, maxUint64)
require.NoError(err)
require.Equal(maxUint64, sum)

sum, err = Add64(maxUint64, 0)
sum, err = Add(maxUint64, 0)
require.NoError(err)
require.Equal(maxUint64, sum)

sum, err = Add64(uint64(1<<62), uint64(1<<62))
sum, err = Add(uint64(1<<62), uint64(1<<62))
require.NoError(err)
require.Equal(uint64(1<<63), sum)

_, err = Add64(1, maxUint64)
_, err = Add(1, maxUint64)
require.ErrorIs(err, ErrOverflow)

_, err = Add64(maxUint64, 1)
_, err = Add(maxUint64, 1)
require.ErrorIs(err, ErrOverflow)

_, err = Add64(maxUint64, maxUint64)
_, err = Add(maxUint64, maxUint64)
require.ErrorIs(err, ErrOverflow)
}

Expand Down Expand Up @@ -63,34 +74,34 @@ func TestSub(t *testing.T) {
require.ErrorIs(err, ErrUnderflow)
}

func TestMul64(t *testing.T) {
func TestMul(t *testing.T) {
require := require.New(t)

got, err := Mul64(0, maxUint64)
got, err := Mul(0, maxUint64)
require.NoError(err)
require.Zero(got)

got, err = Mul64(maxUint64, 0)
got, err = Mul(maxUint64, 0)
require.NoError(err)
require.Zero(got)

got, err = Mul64(uint64(1), uint64(3))
got, err = Mul(uint64(1), uint64(3))
require.NoError(err)
require.Equal(uint64(3), got)

got, err = Mul64(uint64(3), uint64(1))
got, err = Mul(uint64(3), uint64(1))
require.NoError(err)
require.Equal(uint64(3), got)

got, err = Mul64(uint64(2), uint64(3))
got, err = Mul(uint64(2), uint64(3))
require.NoError(err)
require.Equal(uint64(6), got)

got, err = Mul64(maxUint64, 0)
got, err = Mul(maxUint64, 0)
require.NoError(err)
require.Zero(got)

_, err = Mul64(maxUint64-1, 2)
_, err = Mul(maxUint64-1, 2)
require.ErrorIs(err, ErrOverflow)
}

Expand Down
2 changes: 1 addition & 1 deletion utils/sampler/weighted_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *weightedArray) Initialize(weights []uint64) error {

cumulativeWeight := uint64(0)
for i := 0; i < len(s.arr); i++ {
newWeight, err := math.Add64(
newWeight, err := math.Add(
cumulativeWeight,
s.arr[i].cumulativeWeight,
)
Expand Down
2 changes: 1 addition & 1 deletion utils/sampler/weighted_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func CalcWeightedPoW(exponent float64, size int) (uint64, []uint64, error) {
weight := uint64(math.Pow(float64(i+1), exponent))
weights[i] = weight

newWeight, err := safemath.Add64(totalWeight, weight)
newWeight, err := safemath.Add(totalWeight, weight)
if err != nil {
return 0, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion utils/sampler/weighted_best.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type weightedBest struct {
func (s *weightedBest) Initialize(weights []uint64) error {
totalWeight := uint64(0)
for _, weight := range weights {
newWeight, err := safemath.Add64(totalWeight, weight)
newWeight, err := safemath.Add(totalWeight, weight)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion utils/sampler/weighted_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *weightedHeap) Initialize(weights []uint64) error {
// Explicitly performing a shift here allows the compiler to avoid
// checking for negative numbers, which saves a couple cycles
parentIndex := (i - 1) >> 1
newWeight, err := math.Add64(
newWeight, err := math.Add(
s.heap[parentIndex].cumulativeWeight,
s.heap[i].cumulativeWeight,
)
Expand Down
Loading

0 comments on commit 00230cd

Please sign in to comment.