Skip to content

Commit

Permalink
Merge branch 'dev' into make_write_current_stakers_testable
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 authored Sep 23, 2023
2 parents cddf51c + 18324b4 commit e08c437
Show file tree
Hide file tree
Showing 22 changed files with 319 additions and 54 deletions.
15 changes: 9 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ linters-settings:
goimports:
local-prefixes: github.com/ava-labs/avalanchego
depguard:
list-type: blacklist
packages-with-error-message:
- io/ioutil: 'io/ioutil is deprecated. Use package io or os instead.'
- github.com/stretchr/testify/assert: 'github.com/stretchr/testify/require should be used instead.'
- github.com/golang/mock/gomock: 'go.uber.org/mock/gomock should be used instead.'
include-go-root: true
rules:
packages:
deny:
- pkg: "io/ioutil"
desc: io/ioutil is deprecated. Use package io or os instead.
- pkg: "github.com/stretchr/testify/assert"
desc: github.com/stretchr/testify/require should be used instead.
- pkg: "github.com/golang/mock/gomock"
desc: go.uber.org/mock/gomock should be used instead.
errorlint:
# Check for plain type assertions and type switches.
asserts: false
Expand Down
37 changes: 37 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Release Notes

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

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

The plugin version is unchanged at `28` and compatible with versions `v1.10.9 - v1.10.10`.

### Fixes

- Prevented overzelous benching due to dropped AppRequests
- Populated the process file atomically to avoid racy reads

### What's Changed

- Rename platformvm/blocks to platformvm/block by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/1980
- RewardValidatorTx cleanup by @abi87 in https://github.com/ava-labs/avalanchego/pull/1891
- Cancel stale SH actions by @danlaine in https://github.com/ava-labs/avalanchego/pull/2003
- e2e: Switch assertion library from gomega to testify by @marun in https://github.com/ava-labs/avalanchego/pull/1909
- e2e: Add bootstrap checks to migrated kurtosis tests by @marun in https://github.com/ava-labs/avalanchego/pull/1935
- Add `GetTransformSubnetTx` helper by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2047
- Add readme for the staking/local folder by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2046
- use `IsCortinaActivated` helper by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2048
- add `D` upgrade boilerplate by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2049
- e2e: Ensure interchain workflow coverage for the P-Chain by @marun in https://github.com/ava-labs/avalanchego/pull/1882
- e2e: Switch to using default timed context everywhere by @marun in https://github.com/ava-labs/avalanchego/pull/1910
- Remove indentation + confusing comment by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2053
- Delete ErrDelegatorSubset by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2055
- Fix default validator start time by @marun in https://github.com/ava-labs/avalanchego/pull/2058
- Enable workflows to be triggered by merge queue by @marun in https://github.com/ava-labs/avalanchego/pull/2057
- e2e: Migrate staking rewards test from kurtosis by @marun in https://github.com/ava-labs/avalanchego/pull/1767
- Fix LRU documentation comment by @anusha-ctrl in https://github.com/ava-labs/avalanchego/pull/2036
- Ignore AppResponse timeouts for benching by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2066
- trace: provide appName and version from Config by @najeal in https://github.com/ava-labs/avalanchego/pull/1893
- Update perms.WriteFile to write atomically by @marun in https://github.com/ava-labs/avalanchego/pull/2063
- ArchiveDB by @nytzuga in https://github.com/ava-labs/avalanchego/pull/1911

**Full Changelog**: https://github.com/ava-labs/avalanchego/compare/v1.10.10...v1.10.11

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

This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged.
Expand Down
2 changes: 1 addition & 1 deletion ids/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestIDUnmarshalJSON(t *testing.T) {

func TestIDHex(t *testing.T) {
id := ID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}
expected := "617661206c616273000000000000000000000000000000000000000000000000"
expected := "617661206c616273000000000000000000000000000000000000000000000000" //nolint:gosec
require.Equal(t, expected, id.Hex())
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_equal_zero require_len_zero require_equal_len require_nil require_no_error_inline_func"}

function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
golangci-lint run --config .golangci.yml
}

Expand Down
169 changes: 169 additions & 0 deletions tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package c

import (
"math/big"
"strings"

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/plugin/evm"

"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
)

// This test uses the compiled bin for `hashing.sol` as
// well as its ABI contained in `hashing_contract.go`.

var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
require := require.New(ginkgo.GinkgoT())

// Need a gas limit much larger than the standard 21_000 to enable
// the contract to induce a gas price increase
const largeGasLimit = uint64(8_000_000)

// TODO(marun) What is the significance of this value?
gasTip := big.NewInt(1000 * params.GWei)

ginkgo.It("should ensure that the gas price is affected by load", func() {
ginkgo.By("creating a new private network to ensure isolation from other tests")
privateNetwork := e2e.Env.NewPrivateNetwork()

ginkgo.By("allocating a pre-funded key")
key := privateNetwork.GetConfig().FundedKeys[0]
ethAddress := evm.GetEthAddress(key)

ginkgo.By("initializing a coreth client")
node := privateNetwork.GetNodes()[0]
nodeURI := testnet.NodeURI{
NodeID: node.GetID(),
URI: node.GetProcessContext().URI,
}
ethClient := e2e.Env.NewEthClient(nodeURI)

ginkgo.By("initializing a transaction signer")
cChainID, err := ethClient.ChainID(e2e.DefaultContext())
require.NoError(err)
signer := types.NewEIP155Signer(cChainID)
ecdsaKey := key.ToECDSA()
sign := func(tx *types.Transaction) *types.Transaction {
signedTx, err := types.SignTx(tx, signer, ecdsaKey)
require.NoError(err)
return signedTx
}

var contractAddress common.Address
ginkgo.By("deploying an expensive contract", func() {
// Create transaction
nonce, err := ethClient.AcceptedNonceAt(e2e.DefaultContext(), ethAddress)
require.NoError(err)
compiledContract := common.Hex2Bytes(hashingCompiledContract)
tx := types.NewTx(&types.LegacyTx{
Nonce: nonce,
GasPrice: gasTip,
Gas: largeGasLimit,
Value: common.Big0,
Data: compiledContract,
})

// Send the transaction and wait for acceptance
signedTx := sign(tx)
receipt := e2e.SendEthTransaction(ethClient, signedTx)

contractAddress = receipt.ContractAddress
})

var gasPrice *big.Int
ginkgo.By("calling the expensive contract repeatedly until a gas price increase is detected", func() {
// Evaluate the bytes representation of the contract
hashingABI, err := abi.JSON(strings.NewReader(hashingABIJson))
require.NoError(err)
contractData, err := hashingABI.Pack("hashIt")
require.NoError(err)

var initialGasPrice *big.Int
e2e.Eventually(func() bool {
// Check the gas price
var err error
gasPrice, err = ethClient.SuggestGasPrice(e2e.DefaultContext())
require.NoError(err)
if initialGasPrice == nil {
initialGasPrice = gasPrice
tests.Outf("{{blue}}initial gas price is %v{{/}}\n", initialGasPrice)
} else if gasPrice.Cmp(initialGasPrice) > 0 {
// Gas price has increased
tests.Outf("{{blue}}gas price has increased to %v{{/}}\n", gasPrice)
return true
}

// Create the transaction
nonce, err := ethClient.AcceptedNonceAt(e2e.DefaultContext(), ethAddress)
require.NoError(err)
tx := types.NewTx(&types.LegacyTx{
Nonce: nonce,
GasPrice: gasTip,
Gas: largeGasLimit,
To: &contractAddress,
Value: common.Big0,
Data: contractData,
})

// Send the transaction and wait for acceptance
signedTx := sign(tx)
_ = e2e.SendEthTransaction(ethClient, signedTx)

// The gas price will be checked at the start of the next iteration
return false
}, e2e.DefaultTimeout, e2e.DefaultPollingInterval, "failed to see gas price increase before timeout")
})

ginkgo.By("waiting for the gas price to decrease...", func() {
initialGasPrice := gasPrice
e2e.Eventually(func() bool {
var err error
gasPrice, err = ethClient.SuggestGasPrice(e2e.DefaultContext())
require.NoError(err)
tests.Outf("{{blue}}.{{/}}")
return initialGasPrice.Cmp(gasPrice) > 0
}, e2e.DefaultTimeout, e2e.DefaultPollingInterval, "failed to see gas price decrease before timeout")
tests.Outf("\n{{blue}}gas price has decreased to %v{{/}}\n", gasPrice)
})

ginkgo.By("sending funds at the current gas price", func() {
// Create a recipient address
factory := secp256k1.Factory{}
recipientKey, err := factory.NewPrivateKey()
require.NoError(err)
recipientEthAddress := evm.GetEthAddress(recipientKey)

// Create transaction
nonce, err := ethClient.AcceptedNonceAt(e2e.DefaultContext(), ethAddress)
require.NoError(err)
tx := types.NewTx(&types.LegacyTx{
Nonce: nonce,
GasPrice: gasPrice,
Gas: e2e.DefaultGasLimit,
To: &recipientEthAddress,
Value: common.Big0,
})

// Send the transaction and wait for acceptance
signedTx := sign(tx)
_ = e2e.SendEthTransaction(ethClient, signedTx)
})

e2e.CheckBootstrapIsPossible(privateNetwork)
})
})
15 changes: 15 additions & 0 deletions tests/e2e/c/hashing.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT

pragma solidity = 0.8.6;

contract ConsumeGas {

bytes hashVar = bytes("This is the hashing text for the test");

function hashIt() public {
for (uint i=0; i<3700; i++) {
ripemd160(hashVar);
}
}

}
11 changes: 11 additions & 0 deletions tests/e2e/c/hashing_contract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// AUTOMATICALLY GENERATED. DO NOT EDIT!
// Generated from hashing.sol by compile-contract.sh
package c

const (
hashingCompiledContract = "60806040526040518060600160405280602581526020016103ba6025913960009080519060200190610032929190610045565b5034801561003f57600080fd5b50610149565b828054610051906100e8565b90600052602060002090601f01602090048101928261007357600085556100ba565b82601f1061008c57805160ff19168380011785556100ba565b828001600101855582156100ba579182015b828111156100b957825182559160200191906001019061009e565b5b5090506100c791906100cb565b5090565b5b808211156100e45760008160009055506001016100cc565b5090565b6000600282049050600182168061010057607f821691505b602082108114156101145761011361011a565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b610262806101586000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80636f37ecea14610030575b600080fd5b61003861003a565b005b60005b610e7481101561009057600360006040516100589190610112565b602060405180830381855afa158015610075573d6000803e3d6000fd5b5050506040515150808061008890610185565b91505061003d565b50565b600081546100a081610153565b6100aa818661013e565b945060018216600081146100c557600181146100d657610109565b60ff19831686528186019350610109565b6100df85610129565b60005b83811015610101578154818901526001820191506020810190506100e2565b838801955050505b50505092915050565b600061011e8284610093565b915081905092915050565b60008190508160005260206000209050919050565b600081905092915050565b6000819050919050565b6000600282049050600182168061016b57607f821691505b6020821081141561017f5761017e6101fd565b5b50919050565b600061019082610149565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156101c3576101c26101ce565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fdfea2646970667358221220cc5de5cd3c7aa5bda60e63e0f3156691253f7a78191eb336ec6699b38a8a777c64736f6c6343000806003354686973206973207468652068617368696e67207465787420666f72207468652074657374"
hashingABIJson = `[{"inputs":[],"name":"hashIt","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
)
7 changes: 2 additions & 5 deletions tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import (
var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
require := require.New(ginkgo.GinkgoT())

const (
txAmount = 10 * units.Avax // Arbitrary amount to send and transfer
gasLimit = uint64(21000) // Standard gas limit
)
const txAmount = 10 * units.Avax // Arbitrary amount to send and transfer

ginkgo.It("should ensure that funds can be transferred from the C-Chain to the X-Chain and the P-Chain", func() {
ginkgo.By("initializing a new eth client")
Expand All @@ -56,7 +53,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
acceptedNonce,
recipientEthAddress,
big.NewInt(int64(txAmount)),
gasLimit,
e2e.DefaultGasLimit,
gasPrice,
nil,
)
Expand Down
Loading

0 comments on commit e08c437

Please sign in to comment.