-
Notifications
You must be signed in to change notification settings - Fork 778
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
Buffer to Uint8Array cleanup #2607
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6ea9dba
`Buffer` to `Uint8Array` conversion (#2566)
acolytec3 d9c020c
Devp2p status fix
acolytec3 da78efe
Remove buffer detritus
acolytec3 71e3a3a
Switch db to view
acolytec3 f35554d
buffer cleanup
acolytec3 f16ebde
Correctly parse heads from DB
acolytec3 20f41b1
Fix encodings
acolytec3 61894c6
Cast db values to uint8array
acolytec3 b43ab51
Fix db bug in ethash
acolytec3 3e70fd7
Remove unused peerId check
acolytec3 047e916
Add pow miner test
acolytec3 9bcd6dc
Finish test
acolytec3 a23e6fa
Move pow test to integration tests
acolytec3 20d8d8c
client: lint
jochem-brouwer fdf8a79
rename test helper
acolytec3 cd6f431
Add timeout to PoW test
acolytec3 9ec318b
Merge remote-tracking branch 'origin/develop-v7' into devp2p-fixes
acolytec3 affa49b
Fix test runner
acolytec3 75ce24b
remove console log
acolytec3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { parseGethGenesisState } from '@ethereumjs/blockchain' | ||
import { Common, Hardfork } from '@ethereumjs/common' | ||
import { Address } from '@ethereumjs/util' | ||
import { hexToBytes } from 'ethereum-cryptography/utils' | ||
import { removeSync } from 'fs-extra' | ||
import * as tape from 'tape' | ||
|
||
import { Config } from '../../lib' | ||
import { createInlineClient } from '../sim/simutils' | ||
|
||
import type { EthereumClient } from '../../lib' | ||
|
||
const pk = hexToBytes('95a602ff1ae30a2243f400dcf002561b9743b2ae9827b1008e3714a5cc1c0cfe') | ||
const minerAddress = Address.fromPrivateKey(pk) | ||
|
||
async function setupPowDevnet(prefundAddress: Address, cleanStart: boolean) { | ||
if (cleanStart) { | ||
removeSync(`datadir/devnet`) | ||
} | ||
const addr = prefundAddress.toString().slice(2) | ||
const consensusConfig = { ethash: true } | ||
|
||
const defaultChainData = { | ||
config: { | ||
chainId: 123456, | ||
homesteadBlock: 0, | ||
eip150Block: 0, | ||
eip150Hash: '0x0000000000000000000000000000000000000000000000000000000000000000', | ||
eip155Block: 0, | ||
eip158Block: 0, | ||
byzantiumBlock: 0, | ||
constantinopleBlock: 0, | ||
petersburgBlock: 0, | ||
istanbulBlock: 0, | ||
berlinBlock: 0, | ||
londonBlock: 0, | ||
...consensusConfig, | ||
}, | ||
nonce: '0x0', | ||
timestamp: '0x614b3731', | ||
gasLimit: '0x47b760', | ||
difficulty: '0x1', | ||
mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', | ||
coinbase: '0x0000000000000000000000000000000000000000', | ||
number: '0x0', | ||
gasUsed: '0x0', | ||
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', | ||
baseFeePerGas: 7, | ||
} | ||
const extraData = '0x' + '0'.repeat(32) | ||
const chainData = { | ||
...defaultChainData, | ||
extraData, | ||
alloc: { [addr]: { balance: '0x10000000000000000000' } }, | ||
} | ||
const common = Common.fromGethGenesis(chainData, { chain: 'devnet', hardfork: Hardfork.London }) | ||
const customGenesisState = parseGethGenesisState(chainData) | ||
|
||
const config = new Config({ | ||
common, | ||
transports: ['rlpx'], | ||
bootnodes: [], | ||
multiaddrs: [], | ||
discDns: false, | ||
discV4: false, | ||
port: 30304, | ||
maxAccountRange: (BigInt(2) ** BigInt(256) - BigInt(1)) / BigInt(10), | ||
maxFetcherJobs: 10, | ||
datadir: 'devnet', | ||
accounts: [[minerAddress, pk]], | ||
mine: true, | ||
}) | ||
|
||
const client = await createInlineClient(config, common, customGenesisState) | ||
return client | ||
} | ||
|
||
const mineBlockAndstopClient = async (client: EthereumClient, t: tape.Test) => { | ||
await new Promise((resolve) => { | ||
client.config.logger.on('data', (data) => { | ||
if (data.message.includes('Miner: Found PoW solution') === true && client.started) { | ||
t.pass('found a PoW solution') | ||
void client.stop().then(() => { | ||
t.ok(!client.started, 'client stopped successfully') | ||
resolve(undefined) | ||
}) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
tape('PoW client test', { timeout: 60000 }, async (t) => { | ||
t.plan(3) | ||
const client = await setupPowDevnet(minerAddress, true) | ||
t.ok(client.started, 'client started successfully') | ||
await mineBlockAndstopClient(client, t) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the test be:
Right now it starts the client, does not mine, then stops and starts again and then mine a PoW block (this would reflect what we tested using the cli)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there must be some unclearness in how the function is designed. The
setupPowDevnet
function instantiates and starts the client. I've renamed thestopClient
function tomineBlockAndStopClient
to more clearly identify what happens in that helper. I set it up as an async function to make it easier to work with the event listener (which uses a callback rather than a promise interface and isn't naturally async). What actually happens is:setupPowDevnet
creates and starts the clientmineBlockAndStopClient
sets a listener that waits for the first block to be mined and then passes its test and stops the client once it is mined.If we try to stop and then restart the client. A second pow solution is never found so a next block is never mined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok right this ethash problem is beyond the scope of this pr right?