hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Add flag to ignore unknown EIP-2718 types when forking

Open gzeoneth opened this issue 3 years ago • 31 comments

Note to reader: a temporary solution is shared at the bottom of this issue

Certain EVM blockchain (e.g. Arbitrum Nitro) have non-standard EIP-2718 typed transaction that would prevent hardhat fork from working due to Error HH604: Error running JSON-RPC server: Unknown transaction type 106

While it is rarely a good idea to use hardhat fork with these blockchain due to chain specific behavior and precompiles as discussed in https://github.com/NomicFoundation/hardhat/issues/1902, some devs found it helpful to test non-chain specific logic with existing states using hardhat fork. To workaround the Unknown transaction type error, I am proposing to add an optional --fork-ignore-unknown-tx-type flag to skip those transactions.

You can reproduce the error with

hardhat node --fork https://goerli-rollup.arbitrum.io/rpc
  • Arbitrum Nitro specific EIP-2718 types https://github.com/OffchainLabs/go-ethereum/blob/141b0fcdf0e4d8e9e5de3f0466533b86563f2d29/core/types/transaction.go#L48-L54
	ArbitrumDepositTxType         = 100
	ArbitrumUnsignedTxType        = 101
	ArbitrumContractTxType        = 102
	ArbitrumRetryTxType           = 104
	ArbitrumSubmitRetryableTxType = 105
	ArbitrumInternalTxType        = 106
	ArbitrumLegacyTxType          = 120

Here is a draft implementation: https://github.com/gzeoneth/hardhat/tree/2.10.2-gzeon

$ git clone --branch 2.10.2-gzeon https://github.com/gzeoneth/hardhat.git
$ cd hardhat
$ yarn install
$ yarn build
$ touch hardhat.config.js
$ yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

Also published on npm and can be installed with yarn alias

$ yarn add -D hardhat@npm:@gzeoneth/[email protected]
$ yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

27/8/2022: I have upload a patch file here if you don't want to install my package, this is also compatible with a few more hardhat version e.g. 2.9.9, 2.10.2 https://gist.github.com/gzeoneth/99ac30932bf07f91661d7bc621ba1f50

You can install it using patch-package, just follow the step there and put hardhat+2.10.2.patch into the patches folder and run yarn install again. Please note that I did not update the source mapping in this patch file to improve compatibility but it might cause some issue debugging.

10/9/2022: Fixed a few bug with 2.10.2-gzeon-e972f1dda, updated link above

gzeoneth avatar Jul 26 '22 18:07 gzeoneth

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: 63ce06f8-76ab-40ec-8fdc-3fda8f581808

github-actions[bot] avatar Jul 26 '22 18:07 github-actions[bot]

Hey @feuGeneA any opinion on this? Can I move on to create a PR if this approach is ok?

gzeoneth avatar Aug 03 '22 10:08 gzeoneth

Hi @gzeoneth . Thank you for the thoughtful and complete submission. I've just solicited more input from the team. We'll follow up soon.

feuGeneA avatar Aug 08 '22 16:08 feuGeneA

Would really like to be able to fork chains like arbitrum with the introduction of arbitrum nitro.

lzalvin avatar Aug 11 '22 17:08 lzalvin

This issue has been added to our internal backlog. I can't say when we'll be able to prioritize it. But I can say that the more interest is shown here, the more likely we are to work on it sooner rather than later :)

feuGeneA avatar Aug 11 '22 20:08 feuGeneA

Hey, i assumed it was supported to fork arbitrum rinkeby for testing... I am surprised it does not work :( (i based my entire work on this working)

rafinskipg avatar Aug 12 '22 08:08 rafinskipg

Hey, i assumed it was supported to fork arbitrum rinkeby for testing... I am surprised it does not work :( (i based my entire work on this working)

just fyi you can use this as a workaround for now

$ yarn add -D hardhat@npm:@gzeoneth/[email protected]
$ yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

gzeoneth avatar Aug 12 '22 08:08 gzeoneth

Yes I also need this. I am trying to test on a fork of Wanchain and am having the same issue. Thanks!

N00000b avatar Aug 25 '22 07:08 N00000b

looks great. works with hardhat_reset.

await hre.network.provider.request({
                method: 'hardhat_reset',
                params: [
                    {
                        forking: {
                            jsonRpcUrl: rpc,
                            enabled: true,
                            ignoreUnknownTxType: true,
                        },
                    },
                ],
            })

lzalvin avatar Aug 27 '22 00:08 lzalvin

I have upload a patch file here if you don't want to install my package, this is also compatible with a few more hardhat version e.g. 2.9.9, 2.10.2 https://gist.github.com/gzeoneth/195cb16f00eaa32fa868e6c0192616c1 see op for more detail

gzeoneth avatar Aug 27 '22 03:08 gzeoneth

This is absolutely needed, Arbitrum is starting to be one of the most active networks after Ethereum Mainnet. Thanks @gzeoneth for providing an interim solution, will give it a try!

tom-s07 avatar Aug 31 '22 19:08 tom-s07

Definitely a needed change.

I am still getting the error:

Error HH604: Error running JSON-RPC server: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore

after applying the patch. I ran yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

xcellsior avatar Aug 31 '22 20:08 xcellsior

Patch works for me. Any update on this making it into an official release?

ryandgoulding avatar Aug 31 '22 21:08 ryandgoulding

This issue has been added to our internal backlog. I can't say when we'll be able to prioritize it. But I can say that the more interest is shown here, the more likely we are to work on it sooner rather than later :)

more interest is shown

0xyqrz avatar Sep 02 '22 10:09 0xyqrz

My infura and quicknodes Arbitrum mainnet RPC's stopped forking on Friday with this issue. I'm going to try the patch now, just showing interest @0xyqrz. Thanks everyone.

Zalexios avatar Sep 04 '22 17:09 Zalexios

Hey, i assumed it was supported to fork arbitrum rinkeby for testing... I am surprised it does not work :( (i based my entire work on this working)

just fyi you can use this as a workaround for now

$ yarn add -D hardhat@npm:@gzeoneth/[email protected]
$ yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

How can this be used with hardhat tests?

Preston-Harrison avatar Sep 05 '22 04:09 Preston-Harrison

Hey, i assumed it was supported to fork arbitrum rinkeby for testing... I am surprised it does not work :( (i based my entire work on this working)

just fyi you can use this as a workaround for now

$ yarn add -D hardhat@npm:@gzeoneth/[email protected]
$ yarn hardhat node --fork https://rinkeby.arbitrum.io/rpc --fork-ignore-unknown-tx-type true

How can this be used with hardhat tests?

see the first post you can use my patched hardhat or apply the patch file

gzeoneth avatar Sep 05 '22 04:09 gzeoneth

@feuGeneA :+1: interest. thanks!

jacques-martin10 avatar Sep 05 '22 04:09 jacques-martin10

The patch is not working for me when using hardhat_reset like this

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: config.networks.hardhat.forking.url,
          blockNumber,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

Before applying the patch

InternalError: Unknown transaction type 106

After applying the patch + adding ignoreUnknownTxType: true to hardhat_reset

InternalError: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore

Using hardhat 2.10.1

0xchoripan avatar Sep 05 '22 19:09 0xchoripan

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

working fine with me, do you have a sample script?

gzeoneth avatar Sep 06 '22 05:09 gzeoneth

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

where exactly are we supposed to add this aforementioned file if trying to run hardhat tests?

Since the Arbitrum nitro upgrade I have installed the patch, as well as followed the steps laid out above but keep getting an InternalError: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore error.

AbigailTCameron avatar Sep 09 '22 17:09 AbigailTCameron

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

where exactly are we supposed to add this aforementioned file if trying to run hardhat tests?

Since the Arbitrum nitro upgrade I have installed the patch, as well as followed the steps laid out above but keep getting an InternalError: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore error.

I have no idea why it is not working, you can try this alternative patch where it always ignore unknown tx type.

gzeoneth avatar Sep 09 '22 18:09 gzeoneth

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

but which file are we adding the above stipulation to?

AbigailTCameron avatar Sep 09 '22 19:09 AbigailTCameron

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

but which file are we adding the above stipulation to?

Fixed a few bug with 2.10.2-gzeon-e972f1dda, you can use this patch file https://gist.github.com/gzeoneth/99ac30932bf07f91661d7bc621ba1f50

In hardhat.confg.ts you need something like

  networks: {
    hardhat: {
      forking: {
        url: "https://rinkeby.arbitrum.io/rpc",
        ignoreUnknownTxType: true
      }
    }
  },

Then it should work when using the hardhat network.

gzeoneth avatar Sep 09 '22 20:09 gzeoneth

Thank you so much this latest patch finally works.

adichess avatar Sep 09 '22 21:09 adichess

  await network.provider.request({
    method: "hardhat_reset",
    params: [
      {
        forking: {
          jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
          blockNumber: 15216420,
          ignoreUnknownTxType: true,
        },
      },
    ],
  });

where exactly are we supposed to add this aforementioned file if trying to run hardhat tests? Since the Arbitrum nitro upgrade I have installed the patch, as well as followed the steps laid out above but keep getting an InternalError: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore error.

I have no idea why it is not working, you can try this alternative patch where it always ignore unknown tx type.

Could you share your Hardhat config file? I've installed this alternative patch in your latest reply, which helped me bypass the same InternalError: Unknown transaction type 106 as Abbie is experiencing above. This patch has successfully ignored the unknown type 106 error, but now we're getting Error HH604: Error running JSON-RPC server: Invalid URL and I'm assuming it's a configuration issue. We're currently using the following URL for Hardhat forking: https://rinkeby.arbitrum.io/rpc

kjmagill avatar Sep 09 '22 22:09 kjmagill

await network.provider.request({

method: "hardhat_reset",
params: [
  {
    forking: {
      jsonRpcUrl: "https://rinkeby.arbitrum.io/rpc",
      blockNumber: 15216420,
      ignoreUnknownTxType: true,
    },
  },
],

});

where exactly are we supposed to add this aforementioned file if trying to run hardhat tests?

Since the Arbitrum nitro upgrade I have installed the patch, as well as followed the steps laid out above but keep getting an InternalError: Unknown transaction type 106, set --fork-ignore-unknown-tx-type true to ignore error.

I have no idea why it is not working, you can try this alternative patch where it always ignore unknown tx type.

Could you share your Hardhat config file? I've installed this alternative patch in your latest reply, which helped me bypass the same InternalError: Unknown transaction type 106 as Abbie is experiencing above. This patch has successfully ignored the unknown type 106 error, but now we're getting Error HH604: Error running JSON-RPC server: Invalid URL and I'm assuming it's a configuration issue. We're currently using the following URL for Hardhat forking: https://rinkeby.arbitrum.io/rpc

See my previous reply.

gzeoneth avatar Sep 10 '22 04:09 gzeoneth

https://gist.github.com/penandlim/790cebc4ddf204410654624aacb2efb4

I tried to forked the patch posted by @gzeoneth and update it for hardhat 2.11.1 code Seemed to work for me.


https://gist.github.com/penandlim/179a1f4a325c2815fa7f6837240439a5 Updated for 2.11.2

penandlim avatar Sep 13 '22 04:09 penandlim

https://gist.github.com/penandlim/790cebc4ddf204410654624aacb2efb4

I tried to forked the patch posted by @gzeoneth and update it for hardhat 2.11.1 code

Seemed to work for me.

Nice, ya there was a breaking change in 2.11.1

gzeoneth avatar Sep 13 '22 05:09 gzeoneth

https://gist.github.com/penandlim/790cebc4ddf204410654624aacb2efb4 I tried to forked the patch posted by @gzeoneth and update it for hardhat 2.11.1 code Seemed to work for me.

Nice, ya there was a breaking change in 2.11.1

how can i use this?

pwollemi avatar Sep 21 '22 14:09 pwollemi