Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Klaytn support + revise some other ethereum methods #525

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class DefaultEthereumMethods(
"trace_transaction",
)

var arbitrumTraceMethods = listOf(
"arbtrace_call",
"arbtrace_callMany",
"arbtrace_replayBlockTransactions",
"arbtrace_replayTransaction",
"arbtrace_block",
"arbtrace_filter",
"arbtrace_get",
"arbtrace_transaction",
)

val debugMethods = listOf(
"debug_storageRangeAt",
"debug_traceBlock",
Expand Down Expand Up @@ -118,6 +129,30 @@ class DefaultEthereumMethods(
"hmyv2_getCXReceiptByHash",
)

private val klayPossibleNotIndexedMethods = listOf(
"klay_blockNumber",
"klay_getBlockByHash",
"klay_getBlockReceipts",
"klay_getBlockTransactionCountByNumber",
"klay_getBlockWithConsensusInfoByNumber",
"klay_getBlockByNumber",
"klay_getBlockTransactionCountByHash",
"klay_getHeaderByNumber",
"klay_getHeaderByHash",
"klay_getBlockWithConsensusInfoByNumberRange",
"klay_getBlockWithConsensusInfoByHash",
"klay_getDecodedAnchoringTransactionByHash",
"klay_getRawTransactionByBlockNumberAndIndex",
"klay_getRawTransactionByBlockHashAndIndex",
"klay_getRawTransactionByHash",
"klay_getTransactionByBlockNumberAndIndex",
"klay_getTransactionBySenderTxHash",
"klay_getTransactionByBlockHashAndIndex",
"klay_getTransactionByHash",
"klay_getTransactionReceipt",
"klay_getTransactionReceiptBySenderTxHash",
)

private val firstValueMethods = listOf(
"eth_call",
"eth_getStorageAt",
Expand All @@ -141,6 +176,11 @@ class DefaultEthereumMethods(
"hmy_getTransactionCount",
)

private val klaySpecialMethods = listOf(
"klay_sendRawTransaction",
"klay_getTransactionCount",
)

private val headVerifiedMethods = listOf(
"eth_getBlockTransactionCountByNumber",
"eth_getUncleCountByBlockNumber",
Expand All @@ -164,6 +204,71 @@ class DefaultEthereumMethods(
"eth_chainId",
)

private val klayMethods = listOf(
"klay_accountCreated",
"klay_accounts",
"klay_decodeAccountKey",
"klay_getAccountKey",
"klay_getCode",
"klay_encodeAccountKey",
"klay_getAccount",
"klay_getAccount",
"klay_sign",
"klay_isContractAccount",

"klay_getCommittee",
"klay_getCommitteeSize",
"klay_getCouncil",
"klay_getCouncilSize",

"klay_getRewards",
"klay_getStorageAt",
"klay_syncing",

"klay_call",

"klay_estimateGas",

"klay_estimateComputationCost",
"klay_pendingTransactions",
"klay_createAccessList",

"klay_resend",

"klay_chainID",
"klay_clientVersion",
"klay_gasPriceAt",
"klay_gasPrice",
"klay_protocolVersion",
"klay_getChainConfig",
"klay_forkStatus",
"klay_getFilterChanges",
"klay_getFilterLogs",
"klay_newBlockFilter",
"klay_newPendingTransactionFilter",
"klay_uninstallFilter",
"klay_unsubscribe",
"klay_getLogs",
"klay_subscribe",
"klay_newFilter",

"klay_feeHistory",
"klay_lowerBoundGasPrice",
"klay_upperBoundGasPrice",
"klay_maxPriorityFeePerGas",

"klay_getStakingInfo",
"klay_sha3",
"klay_recoverFromTransaction",
"klay_recoverFromMessage",
"klay_getProof",
"klay_nodeAddress",

// they exist, but i have doubts that we need to expose them
// "klay_rewardbase"
// "klay_isParallelDBWrite"
// "klay_isSenderTxHashIndexingEnabled"
)
private val harmonyMethods = listOf(
"hmy_newFilter",
"hmy_newBlockFilter",
Expand Down Expand Up @@ -239,11 +344,11 @@ class DefaultEthereumMethods(

override fun createQuorumFor(method: String): CallQuorum {
return when {
possibleNotIndexedMethods.contains(method) || harmonyPossibleNotIndexedMethods.contains(method) -> NotNullQuorum()
specialMethods.contains(method) || harmonySpecialMethods.contains(method) -> {
possibleNotIndexedMethods.contains(method) || harmonyPossibleNotIndexedMethods.contains(method) || klayPossibleNotIndexedMethods.contains(method) -> NotNullQuorum()
specialMethods.contains(method) || harmonySpecialMethods.contains(method) || klaySpecialMethods.contains(method) -> {
when (method) {
"eth_getTransactionCount", "hmy_getTransactionCount" -> MaximumValueQuorum()
"eth_sendRawTransaction", "hmy_sendRawStakingTransaction", "hmy_sendRawTransaction" -> BroadcastQuorum()
"eth_getTransactionCount", "hmy_getTransactionCount", "klay_getTransactionCount" -> MaximumValueQuorum()
"eth_sendRawTransaction", "hmy_sendRawStakingTransaction", "hmy_sendRawTransaction", "klay_sendRawTransaction" -> BroadcastQuorum()
else -> AlwaysQuorum()
}
}
Expand All @@ -263,10 +368,27 @@ class DefaultEthereumMethods(

private fun getChainSpecificMethods(chain: Chain): List<String> {
return when (chain) {
Chain.OPTIMISM__MAINNET, Chain.MANTLE__MAINNET ->
Chain.OPTIMISM__MAINNET, Chain.OPTIMISM__SEPOLIA ->
listOf(
"optimism_outputAtBlock",
"optimism_syncStatus",
"optimism_rollupConfig",
"optimism_version",
"rollup_gasPrices",
)
Chain.SCROLL__MAINNET, Chain.SCROLL__SEPOLIA ->
listOf(
"scroll_estimateL1DataFee",
)
Chain.KLAYTN__MAINNET, Chain.KLAYTN__BAOBAB ->
klayMethods
.plus(klaySpecialMethods)
.plus(klayPossibleNotIndexedMethods)
Chain.MANTLE__MAINNET, Chain.MANTLE__SEPOLIA ->
listOf(
"rollup_gasPrices",
"eth_getBlockRange",
)
Chain.POLYGON__MAINNET, Chain.POLYGON__MUMBAI -> listOf(
"bor_getAuthor",
"bor_getCurrentValidators",
Expand All @@ -276,7 +398,7 @@ class DefaultEthereumMethods(
"eth_getRootHash",
)

Chain.POLYGON_ZKEVM__MAINNET -> listOf(
Chain.POLYGON_ZKEVM__MAINNET, Chain.POLYGON_ZKEVM__CARDONA -> listOf(
"zkevm_consolidatedBlockNumber",
"zkevm_isBlockConsolidated",
"zkevm_isBlockVirtualized",
Expand All @@ -288,7 +410,7 @@ class DefaultEthereumMethods(
"zkevm_getBroadcastURI",
)

Chain.ZKSYNC__MAINNET -> listOf(
Chain.ZKSYNC__MAINNET, Chain.ZKSYNC__SEPOLIA -> listOf(
"zks_estimateFee",
"zks_estimateGasL1ToL2",
"zks_getAllAccountBalances",
Expand Down Expand Up @@ -409,14 +531,24 @@ class DefaultEthereumMethods(
return json.toByteArray()
}

override fun getGroupMethods(groupName: String): Set<String> =
when (groupName) {
override fun getGroupMethods(groupName: String): Set<String> {
val isArbitrum = when (chain) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    private fun getTraceMethods(): List<String> {
        return when (chain) {
            Chain.ARBITRUM__MAINNET, ... other chains -> listOf("arb_methods")
            else -> traceMethods
        }
    }

Chain.ARBITRUM__MAINNET, Chain.ARB_BLUEBERRY__TESTNET -> true
Chain.ARBITRUM__SEPOLIA, Chain.ARBITRUM_NOVA__MAINNET -> true
else -> false
}
return when (groupName) {
"filter" -> filterMethods
"trace" -> traceMethods
"trace" -> if (isArbitrum) {
arbitrumTraceMethods
} else {
traceMethods
}
"debug" -> debugMethods
"default" -> getSupportedMethods()
else -> emptyList()
}.toSet()
}

override fun getSupportedMethods(): Set<String> {
return allowedMethods.plus(hardcodedMethods).toSortedSet()
Expand Down
Loading