Skip to content

Commit

Permalink
Merge branch 'master' into geth-v1.13.14-sq
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur authored Sep 2, 2024
2 parents a87d4f8 + 252592a commit 356a93d
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 61 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ jobs:
run: scripts/mock.gen.sh
- shell: bash
run: .github/workflows/check-clean-branch.sh
test_build_image:
name: Image build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check image build
shell: bash
run: bash -x scripts/tests.build_docker_image.sh
test_build_antithesis_images:
name: Build Antithesis images
runs-on: ubuntu-latest
Expand Down
29 changes: 3 additions & 26 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,9 @@ func (bc *BlockChain) Reject(block *types.Block) error {
return fmt.Errorf("failed to write delete block batch: %w", err)
}

// Remove the block from the block cache (ignore return value of whether it was in the cache)
_ = bc.blockCache.Remove(block.Hash())

return nil
}

Expand Down Expand Up @@ -1707,32 +1710,6 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
log.Debug(reason.String())
}

func (bc *BlockChain) RemoveRejectedBlocks(start, end uint64) error {
batch := bc.db.NewBatch()

for i := start; i < end; i++ {
hashes := rawdb.ReadAllHashes(bc.db, i)
canonicalBlock := bc.GetBlockByNumber((i))
if canonicalBlock == nil {
return fmt.Errorf("failed to retrieve block by number at height %d", i)
}
canonicalHash := canonicalBlock.Hash()
for _, hash := range hashes {
if hash == canonicalHash {
continue
}
rawdb.DeleteBlock(batch, hash, i)
}

if err := batch.Write(); err != nil {
return fmt.Errorf("failed to write delete rejected block batch at height %d", i)
}
batch.Reset()
}

return nil
}

// reprocessBlock reprocesses a previously accepted block. This is often used
// to regenerate previously pruned state tries.
func (bc *BlockChain) reprocessBlock(parent *types.Block, current *types.Block) (common.Hash, error) {
Expand Down
1 change: 1 addition & 0 deletions core/test_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ func TestAcceptNonCanonicalBlock(t *testing.T, create func(db ethdb.Database, gs
if err := blockchain.Reject(chain1[i]); err != nil {
t.Fatal(err)
}
require.False(t, blockchain.HasBlock(chain1[i].Hash(), chain1[i].NumberU64()))
}

lastAcceptedBlock := blockchain.LastConsensusAcceptedBlock()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.12
require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/antithesishq/antithesis-sdk-go v0.3.8
github.com/ava-labs/avalanchego v1.11.11-0.20240821175119-35c66e33f0dc
github.com/ava-labs/avalanchego v1.11.11-monitoring-url.0.20240827194054-0117ab96791c
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/antithesishq/antithesis-sdk-go v0.3.8 h1:OvGoHxIcOXFJLyn9IJQ5DzByZ3YVAWNBc394ObzDRb8=
github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.11-0.20240821175119-35c66e33f0dc h1:cUz1N+LJIeQAR0Z6zTBiuZ7s8GqIE5QQbRWs423VFRA=
github.com/ava-labs/avalanchego v1.11.11-0.20240821175119-35c66e33f0dc/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM=
github.com/ava-labs/avalanchego v1.11.11-monitoring-url.0.20240827194054-0117ab96791c h1:WAbq2clkTkoxELkCePFe7sqwOvD32SZPzoWtciUmzQI=
github.com/ava-labs/avalanchego v1.11.11-monitoring-url.0.20240827194054-0117ab96791c/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM=
github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 h1:6aIHp7wbyGVYdhHVQUbG7BEcbCMEQ5SYopPPJyipyvk=
github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180/go.mod h1:/wNBVq7J7wlC2Kbov7kk6LV5xZvau7VF9zwTVOeyAjY=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/gossiper_eth_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {

// Txs must be submitted over the API to be included in push gossip.
// (i.e., txs received via p2p are not included in push gossip)
vm.eth.APIBackend.SendTx(context.Background(), tx)
err = vm.eth.APIBackend.SendTx(context.Background(), tx)
assert.NoError(err)
assert.False(txRequested, "tx should not be requested")

Expand Down
11 changes: 0 additions & 11 deletions precompile/contracts/warp/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/ava-labs/subnet-evm/predicate"
"github.com/ava-labs/subnet-evm/utils"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

const pChainHeight uint64 = 1337
Expand All @@ -49,7 +48,6 @@ var (
numTestVdrs = 10_000
testVdrs []*testValidator
vdrs map[ids.NodeID]*validators.GetValidatorOutput
tests []signatureTest

predicateTests = make(map[string]testutils.PredicateTest)
)
Expand Down Expand Up @@ -132,15 +130,6 @@ func newTestValidator() *testValidator {
}
}

type signatureTest struct {
name string
stateF func(*gomock.Controller) validators.State
quorumNum uint64
quorumDen uint64
msgF func(*require.Assertions) *avalancheWarp.Message
err error
}

// createWarpMessage constructs a signed warp message using the global variable [unsignedMsg]
// and the first [numKeys] signatures from [blsSignatures]
func createWarpMessage(numKeys int) *avalancheWarp.Message {
Expand Down
44 changes: 27 additions & 17 deletions precompile/contracts/warp/signature_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,31 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorsmock"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/set"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

// This test copies the test coverage from https://github.com/ava-labs/avalanchego/blob/v1.10.0/vms/platformvm/warp/signature_test.go#L137.
type signatureTest struct {
name string
stateF func(*gomock.Controller) validators.State
quorumNum uint64
quorumDen uint64
msgF func(*require.Assertions) *avalancheWarp.Message
err error
}

// This test copies the test coverage from https://github.com/ava-labs/avalanchego/blob/0117ab96/vms/platformvm/warp/signature_test.go#L137.
// These tests are only expected to fail if there is a breaking change in AvalancheGo that unexpectedly changes behavior.
func TestSignatureVerification(t *testing.T) {
tests = []signatureTest{
tests := []signatureTest{
{
name: "can't get subnetID",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, errTest)
return state
},
Expand All @@ -50,7 +60,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "can't get validator set",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(nil, errTest)
return state
Expand All @@ -77,7 +87,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "weight overflow",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(map[ids.NodeID]*validators.GetValidatorOutput{
testVdrs[0].nodeID: {
Expand Down Expand Up @@ -117,7 +127,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "invalid bit set index",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -147,7 +157,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "unknown index",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -180,7 +190,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "insufficient weight",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -224,7 +234,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "can't parse sig",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -258,7 +268,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "no validators",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(nil, nil)
return state
Expand Down Expand Up @@ -293,7 +303,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "invalid signature (substitute)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -337,7 +347,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "invalid signature (missing one)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -377,7 +387,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "invalid signature (extra one)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -422,7 +432,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "valid signature",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -466,7 +476,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "valid signature (boundary)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(vdrs, nil)
return state
Expand Down Expand Up @@ -510,7 +520,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "valid signature (missing key)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(map[ids.NodeID]*validators.GetValidatorOutput{
testVdrs[0].nodeID: {
Expand Down Expand Up @@ -571,7 +581,7 @@ func TestSignatureVerification(t *testing.T) {
{
name: "valid signature (duplicate key)",
stateF: func(ctrl *gomock.Controller) validators.State {
state := validators.NewMockState(ctrl)
state := validatorsmock.NewState(ctrl)
state.EXPECT().GetSubnetID(gomock.Any(), sourceChainID).Return(sourceSubnetID, nil)
state.EXPECT().GetValidatorSet(gomock.Any(), pChainHeight, sourceSubnetID).Return(map[ids.NodeID]*validators.GetValidatorOutput{
testVdrs[0].nodeID: {
Expand Down
1 change: 0 additions & 1 deletion scripts/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ source "$SUBNET_EVM_PATH"/scripts/versions.sh

# WARNING: this will use the most recent commit even if there are un-committed changes present
BUILD_IMAGE_ID=${BUILD_IMAGE_ID:-"${CURRENT_BRANCH}"}
DOCKERHUB_TAG=${SUBNET_EVM_COMMIT::8}

VM_ID=${VM_ID:-"${DEFAULT_VM_ID}"}
if [[ "${VM_ID}" != "${DEFAULT_VM_ID}" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ else
SUBNET_EVM_COMMIT="$(git --git-dir="$SUBNET_EVM_PATH/.git" rev-parse HEAD || :)"
fi

# Shared between ./scripts/build_docker_image.sh and ./scripts/tests.build_docker_image.sh
DOCKERHUB_TAG=${SUBNET_EVM_COMMIT::8}

echo "Using branch: ${CURRENT_BRANCH}"

# Static compilation
Expand Down
19 changes: 19 additions & 0 deletions scripts/tests.build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -euo pipefail

# Sanity check the image build by attempting to build and run the image without error.

# Directory above this script
SUBNET_EVM_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$SUBNET_EVM_PATH"/scripts/constants.sh

# Build a local image
"${SUBNET_EVM_PATH}"/scripts/build_docker_image.sh

# Check that the image can be run and contains the plugin
echo "Checking version of the plugin provided by the image"
docker run -t --rm "${DOCKERHUB_REPO}:${DOCKERHUB_TAG}" /avalanchego/build/plugins/"${DEFAULT_VM_ID}" --version
echo "" # --version output doesn't include a newline
echo "Successfully checked image build"
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# shellcheck disable=SC2034

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'35c66e33'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'0117ab96'}
GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'}

# This won't be used, but it's here to make code syncs easier
Expand Down
3 changes: 2 additions & 1 deletion warp/validators/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorsmock"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/subnet-evm/utils"
"github.com/stretchr/testify/require"
Expand All @@ -22,7 +23,7 @@ func TestGetValidatorSetPrimaryNetwork(t *testing.T) {
mySubnetID := ids.GenerateTestID()
otherSubnetID := ids.GenerateTestID()

mockState := validators.NewMockState(ctrl)
mockState := validatorsmock.NewState(ctrl)
snowCtx := utils.TestSnowContext()
snowCtx.SubnetID = mySubnetID
snowCtx.ValidatorState = mockState
Expand Down

0 comments on commit 356a93d

Please sign in to comment.