Skip to content

Commit

Permalink
Merge branch 'master' into sync-upstream-v0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
debaghtk committed Mar 7, 2024
2 parents e8433a1 + b4b595e commit 46d40e0
Show file tree
Hide file tree
Showing 50 changed files with 808 additions and 1,679 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

# review whenever someone opens a pull request.

* @ceyonur @darioush @aaronbuchwald
* @ceyonur @darioush

25 changes: 14 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:

env:
tmpnet_data_path: ~/.tmpnet/networks/1000

jobs:
lint_test:
name: Lint
Expand Down Expand Up @@ -88,7 +91,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: subnet-evm-e2e-logs-precompile
path: /tmp/network-runner-root-data*/
path: /tmp/e2e-test/precompile-data
retention-days: 5
e2e_warp:
name: e2e warp tests
Expand Down Expand Up @@ -124,14 +127,14 @@ jobs:
run: ./scripts/build.sh /tmp/e2e-test/avalanchego/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
- name: Run Warp E2E Tests
shell: bash
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego DATA_DIR=/tmp/e2e-test/warp-data ./scripts/run_ginkgo_warp.sh
- name: Upload Artifact
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego ./scripts/run_ginkgo_warp.sh
- name: Upload tmpnet network dir for warp testing
if: always()
uses: actions/upload-artifact@v4
with:
name: subnet-evm-e2e-logs-warp
path: /tmp/network-runner-root-data*/
retention-days: 5
name: warp-tmpnet-data
path: ${{ env.tmpnet_data_path }}
if-no-files-found: error
e2e_load:
name: e2e load tests
runs-on: ubuntu-latest
Expand All @@ -153,14 +156,14 @@ jobs:
run: ./scripts/build.sh /tmp/e2e-test/avalanchego/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy
- name: Run E2E Load Tests
shell: bash
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego DATA_DIR=/tmp/e2e-test/load-data ./scripts/run_ginkgo_load.sh
- name: Upload Artifact
run: AVALANCHEGO_BUILD_PATH=/tmp/e2e-test/avalanchego ./scripts/run_ginkgo_load.sh
- name: Upload tmpnet network dir for load testing
if: always()
uses: actions/upload-artifact@v4
with:
name: subnet-evm-e2e-logs-load
path: /tmp/network-runner-root-data*/
retention-days: 5
name: load-tmpnet-data
path: ${{ env.tmpnet_data_path }}
if-no-files-found: error

build_image:
name: Build Docker Image
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.5.11] [email protected] (Protocol Version: 31)
[v0.6.0] [email protected] (Protocol Version: 33)
[v0.6.1] [email protected] (Protocol Version: 33)
[v0.6.2] [email protected] (Protocol Version: 34)
```

## API
Expand Down
3 changes: 3 additions & 0 deletions accounts/abi/bind/precompilebind/precompile_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func createPrecompileHook(abifilename string, template string) bind.BindHook {
for key := range allowlist.AllowListABI.Methods {
delete(funcs, key)
}
for events := range allowlist.AllowListABI.Events {
delete(contract.Events, events)
}
}

precompileContract := &tmplPrecompileContract{
Expand Down
10 changes: 5 additions & 5 deletions accounts/abi/bind/precompilebind/precompile_bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ var bindTests = []struct {
require.NoError(t, err)
require.Equal(t, testBytes, unpacked.BytesTest)
gasCost := GetTestEventGasCost(testEventData)
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + contract.LogDataGas, gasCost)
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas + contract.LogDataGas, gasCost)
topics, data, err = PackEmptyEvent()
require.NoError(t, err)
Expand All @@ -553,7 +553,7 @@ var bindTests = []struct {
require.Equal(t, eventID, topics[0])
require.Equal(t, testAddr.Hash(), topics[1])
require.Equal(t, 0, len(data))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas, GetIndexedEventGasCost())
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas, GetIndexedEventGasCost())
testMixedData := MixedEventData{
Num: testInt,
Expand All @@ -567,7 +567,7 @@ var bindTests = []struct {
unpackedMixedData, err := UnpackMixedEventData(data)
require.NoError(t, err)
require.Equal(t, testMixedData, unpackedMixedData)
require.Equal(t, contract.LogGas + contract.LogTopicGas + contract.LogDataGas, GetMixedEventGasCost(testMixedData))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + contract.LogDataGas, GetMixedEventGasCost(testMixedData))
testDynamicData := DynamicEventData{
Str: "test",
Expand All @@ -581,15 +581,15 @@ var bindTests = []struct {
unpackedDynamicData, err := UnpackDynamicEventData(data)
require.NoError(t, err)
require.Equal(t, testDynamicData, unpackedDynamicData)
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + 2 * contract.LogDataGas, GetDynamicEventGasCost(testDynamicData))
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas + 2 * contract.LogDataGas, GetDynamicEventGasCost(testDynamicData))
topics, data, err = PackUnnamedEvent(testUint, testUint)
require.NoError(t, err)
eventID = IEventerABI.Events["unnamed"].ID
require.Len(t, topics, 3)
require.Equal(t, eventID, topics[0])
require.Equal(t, 0, len(data))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas, GetUnnamedEventGasCost())
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas, GetUnnamedEventGasCost())
`,
"",
false,
Expand Down
5 changes: 3 additions & 2 deletions accounts/abi/bind/precompilebind/precompile_event_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ accessibleState.GetStateDB().AddLog(
{{range .Contract.Events}}
{{$event := .}}
{{$createdDataStruct := false}}
{{$topicCount := 0}}
{{$topicCount := 1}}
{{- range .Normalized.Inputs}}
{{- if .Indexed}}
{{$topicCount = add $topicCount 1}}
Expand All @@ -81,8 +81,9 @@ accessibleState.GetStateDB().AddLog(
// The gas cost of the non-indexed data depends on the data type and the data size.
func Get{{.Normalized.Name}}EventGasCost({{if $createdDataStruct}} data {{.Normalized.Name}}EventData{{end}}) uint64 {
gas := contract.LogGas // base gas cost
{{if $topicCount | lt 0}}
{{if $topicCount | lt 1}}
// Add topics gas cost ({{$topicCount}} topics)
// Topics always include the signature hash of the event. The rest are the indexed event arguments.
gas += contract.LogTopicGas * {{$topicCount}}
{{end}}
Expand Down
24 changes: 13 additions & 11 deletions cmd/precompilegen/template-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ For testing take a look at other precompile tests in contract_test.go and config
See the tutorial in <https://docs.avax.network/subnets/hello-world-precompile-tutorial> for more information about precompile development.

General guidelines for precompile development:

1- Set a suitable config key in generated module.go. E.g: "yourPrecompileConfig"
2- Read the comment and set a suitable contract address in generated module.go. E.g:
ContractAddress = common.HexToAddress("ASUITABLEHEXADDRESS")
3- It is recommended to only modify code in the highlighted areas marked with "CUSTOM CODE STARTS HERE". Typically, custom codes are required in only those areas.
Modifying code outside of these areas should be done with caution and with a deep understanding of how these changes may impact the EVM.
4- Set gas costs in generated contract.go
5- Force import your precompile package in precompile/registry/registry.go
6- Add your config unit tests under generated package config_test.go
7- Add your contract unit tests under generated package contract_test.go
8- Additionally you can add a full-fledged VM test for your precompile under plugin/vm/vm_test.go. See existing precompile tests for examples.
9- Add your solidity interface and test contract to contracts/contracts
10- Write solidity contract tests for your precompile in contracts/contracts/test
11- Write TypeScript DS-Test counterparts for your solidity tests in contracts/test
12- Create your genesis with your precompile enabled in tests/precompile/genesis/
13- Create e2e test for your solidity test in tests/precompile/solidity/suites.go
14- Run your e2e precompile Solidity tests with './scripts/run_ginkgo.sh`
4- If you have any event defined in your precompile, review the generated event.go file and set your event gas costs. You should also emit your event in your function in the contract.go file.
5- Set gas costs in generated contract.go
6- Force import your precompile package in precompile/registry/registry.go
7- Add your config unit tests under generated package config_test.go
8- Add your contract unit tests under generated package contract_test.go
9- Additionally you can add a full-fledged VM test for your precompile under plugin/vm/vm_test.go. See existing precompile tests for examples.
10- Add your solidity interface and test contract to contracts/contracts
11- Write solidity contract tests for your precompile in contracts/contracts/test
12- Write TypeScript DS-Test counterparts for your solidity tests in contracts/test
13- Create your genesis with your precompile enabled in tests/precompile/genesis/
14- Create e2e test for your solidity test in tests/precompile/solidity/suites.go
15- Run your e2e precompile Solidity tests with './scripts/run_ginkgo.sh`
1 change: 1 addition & 0 deletions compatibility.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rpcChainVMProtocolVersion": {
"v0.6.2": 34,
"v0.6.1": 33,
"v0.6.0": 33,
"v0.5.11": 31,
Expand Down
6 changes: 4 additions & 2 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ type Config struct {
// DefaultConfig contains the default configurations for the transaction
// pool.
var DefaultConfig = Config{
Journal: "transactions.rlp",
// If we re-enable txpool journaling, we should also add the saved local
// transactions to the p2p gossip on startup.
Journal: "",
Rejournal: time.Hour,

PriceLimit: 1,
Expand All @@ -213,7 +215,7 @@ var DefaultConfig = Config{
AccountQueue: 64,
GlobalQueue: 1024,

Lifetime: 3 * time.Hour,
Lifetime: 10 * time.Minute,
}

// sanitize checks the provided user configurations and changes anything that's
Expand Down
5 changes: 1 addition & 4 deletions core/txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
var (
// testTxPoolConfig is a transaction pool configuration without stateful disk
// sideeffects used during testing.
testTxPoolConfig Config
testTxPoolConfig = DefaultConfig

// eip1559Config is a chain config with EIP-1559 enabled at block 0.
eip1559Config *params.ChainConfig
Expand All @@ -77,9 +77,6 @@ var (
)

func init() {
testTxPoolConfig = DefaultConfig
testTxPoolConfig.Journal = ""

cpy := *params.TestChainConfig
eip1559Config = &cpy
eip1559Config.SubnetEVMTimestamp = utils.NewUint64(0)
Expand Down
9 changes: 8 additions & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,14 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
if err := ctx.Err(); err != nil {
return err
}
return b.eth.txPool.AddLocal(signedTx)
if err := b.eth.txPool.AddLocal(signedTx); err != nil {
return err
}

// We only enqueue transactions for push gossip if they were submitted over the RPC and
// added to the mempool.
b.eth.gossiper.Add(signedTx)
return nil
}

func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
Expand Down
10 changes: 9 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ type Settings struct {
MaxBlocksPerRequest int64 // Maximum number of blocks to serve per getLogs request
}

// PushGossiper sends pushes pending transactions to peers until they are
// removed from the mempool.
type PushGossiper interface {
Add(*types.Transaction)
}

// Ethereum implements the Ethereum full node service.
type Ethereum struct {
config *Config

// Handlers
txPool *txpool.TxPool
blockchain *core.BlockChain
gossiper PushGossiper

// DB interfaces
chainDb ethdb.Database // Block chain database
Expand Down Expand Up @@ -117,6 +124,7 @@ func roundUpCacheSize(input int, allocSize int) int {
func New(
stack *node.Node,
config *Config,
gossiper PushGossiper,
chainDb ethdb.Database,
settings Settings,
lastAcceptedHash common.Hash,
Expand Down Expand Up @@ -150,6 +158,7 @@ func New(

eth := &Ethereum{
config: config,
gossiper: gossiper,
chainDb: chainDb,
eventMux: new(event.TypeMux),
accountManager: stack.AccountManager(),
Expand Down Expand Up @@ -228,7 +237,6 @@ func New(

eth.bloomIndexer.Start(eth.blockchain)

config.TxPool.Journal = ""
eth.txPool = txpool.NewTxPool(config.TxPool, eth.blockchain.Config(), eth.blockchain)

eth.miner = miner.New(eth, &config.Miner, eth.blockchain.Config(), eth.EventMux(), eth.engine, clock)
Expand Down
Loading

0 comments on commit 46d40e0

Please sign in to comment.