Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c053761
block -> refactor: reworked header class with static factory instanti…
holgerd77 Sep 21, 2020
ff46c55
block -> refactoring: added new static factory helpers to block class
holgerd77 Sep 21, 2020
dd228bc
block -> refactor: fix build errors, remove unused imports, unpad num…
jochem-brouwer Sep 24, 2020
608d804
block -> rename Header to BlockHeader
jochem-brouwer Sep 28, 2020
17a33a8
block/tx -> fix block tests
jochem-brouwer Sep 28, 2020
72b5b78
block -> enforce BNs on fields which are interpreted as numbers
jochem-brouwer Sep 28, 2020
8adcdf9
block -> edge case in toBN
jochem-brouwer Sep 29, 2020
8987003
ethash -> make ethash compatible with block
jochem-brouwer Sep 29, 2020
5f5e9f2
Merge branch 'master' into refactor-block-library
ryanio Oct 7, 2020
5351fb8
have validateTransactions return a string[] (https://github.com/ether…
ryanio Oct 7, 2020
ce1dac1
let => const
ryanio Oct 7, 2020
526f986
set default param to resolve js runtime check
ryanio Oct 7, 2020
75689e6
continue refactoring and simplifying methods
ryanio Oct 8, 2020
8923f71
api updates
ryanio Oct 8, 2020
6a2c193
continuing work
ryanio Oct 8, 2020
381f5e1
inline buffer validations. add checks for extraData, mixHash and nonce
ryanio Oct 8, 2020
7eecf80
various fixups
ryanio Oct 8, 2020
395c6f8
continuing various work
ryanio Oct 9, 2020
be5c8d2
continuing work and refactoring
ryanio Oct 9, 2020
7fa486d
Merge branch 'master' into refactor-block-library
ryanio Oct 9, 2020
91d45d7
re-add timestamp to genesis (for rinkeby)
ryanio Oct 9, 2020
7e788c3
last fixups
ryanio Oct 9, 2020
bc459e8
update readme, benchmarks
ryanio Oct 9, 2020
ea8a401
update vm readme, simplify validate
ryanio Oct 10, 2020
b694010
fix timestamp validation
ryanio Oct 10, 2020
1f66378
use native eq
ryanio Oct 10, 2020
9f9bab0
make blockchain optional in block.validate()
ryanio Oct 10, 2020
7ce9132
fixups
ryanio Oct 10, 2020
a5d3d14
remove BLOCK_difficulty_GivenAsList from skip list (https://github.co…
ryanio Oct 12, 2020
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
Prev Previous commit
Next Next commit
block -> rename Header to BlockHeader
  • Loading branch information
jochem-brouwer committed Sep 28, 2020
commit 608d804f9876844e37ec9dd0b33fe10aa6a27740
20 changes: 10 additions & 10 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { BaseTrie as Trie } from 'merkle-patricia-tree'
import { BN, rlp, keccak256, KECCAK256_RLP, baToJSON } from 'ethereumjs-util'
import Common from '@ethereumjs/common'
import { Transaction, TxOptions } from '@ethereumjs/tx'
import { Header } from './header'
import { BlockHeader } from './header'
import { Blockchain, BlockData, BlockOptions } from './types'

/**
* An object that represents the block
*/
export class Block {
public readonly header: Header
public readonly header: BlockHeader
public readonly transactions: Transaction[] = []
public readonly uncleHeaders: Header[] = []
public readonly uncleHeaders: BlockHeader[] = []
public readonly txTrie = new Trie()

private readonly _common: Common
Expand All @@ -26,7 +26,7 @@ export class Block {
const txsData = blockData.transactions || []
const uncleHeadersData = blockData.uncleHeaders || []

const header = Header.fromHeaderData(headerData, opts)
const header = BlockHeader.fromHeaderData(headerData, opts)

// parse transactions
let transactions = []
Expand All @@ -37,7 +37,7 @@ export class Block {
// parse uncle headers
let uncleHeaders = []
for (const uncleHeaderData of uncleHeadersData) {
uncleHeaders.push(Header.fromHeaderData(uncleHeaderData, opts))
uncleHeaders.push(BlockHeader.fromHeaderData(uncleHeaderData, opts))
}

return new Block(header, transactions, uncleHeaders, opts)
Expand All @@ -64,7 +64,7 @@ export class Block {
const txsData = values[1] || []
const uncleHeadersData = values[2] || []

const header = Header.fromValuesArray(headerArray, opts)
const header = BlockHeader.fromValuesArray(headerArray, opts)

// parse transactions
let transactions = []
Expand All @@ -75,7 +75,7 @@ export class Block {
// parse uncle headers
let uncleHeaders = []
for (const uncleHeaderData of uncleHeadersData) {
uncleHeaders.push(Header.fromRLPSerializedHeader(uncleHeaderData, opts))
uncleHeaders.push(BlockHeader.fromRLPSerializedHeader(uncleHeaderData, opts))
}

return new Block(header, transactions, uncleHeaders, opts)
Expand All @@ -92,9 +92,9 @@ export class Block {
* @param options - The options for this block (like the chain setup)
*/
constructor(
header: Header,
header: BlockHeader,
transactions: Transaction[],
uncleHeaders: Header[],
uncleHeaders: BlockHeader[],
//data: Buffer | [Buffer[], Buffer[], Buffer[]] | BlockData = {},
opts: BlockOptions = {},
) {
Expand Down Expand Up @@ -266,7 +266,7 @@ export class Block {
await this.txTrie.put(rlp.encode(txIndex), tx.serialize())
}

private _validateUncleHeader(uncleHeader: Header, blockchain: Blockchain) {
private _validateUncleHeader(uncleHeader: BlockHeader, blockchain: Blockchain) {
// TODO: Validate that the uncle header hasn't been included in the blockchain yet.
// This is not possible in ethereumjs-blockchain since this PR was merged:
// https://github.com/ethereumjs/ethereumjs-blockchain/pull/47
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/header-from-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Header } from './header'
import { BlockHeader } from './header'
import { KECCAK256_NULL, toBuffer } from 'ethereumjs-util'
import { BlockOptions } from './types'

Expand All @@ -9,7 +9,7 @@ import { BlockOptions } from './types'
* @param chainOptions - An object describing the blockchain
*/
export default function blockHeaderFromRpc(blockParams: any, options?: BlockOptions) {
const blockHeader = Header.fromHeaderData(
const blockHeader = BlockHeader.fromHeaderData(
{
parentHash: blockParams.parentHash,
uncleHash: blockParams.sha3Uncles,
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { checkBufferLength } from './util'
/**
* An object that represents the block header
*/
export class Header {
export class BlockHeader {
public readonly parentHash: Buffer
public readonly uncleHash: Buffer
public readonly coinbase: Buffer
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Header {
nonce,
} = headerData

return new Header(
return new BlockHeader(
parentHash ? checkBufferLength(toBuffer(parentHash), 32) : zeros(32),
uncleHash ? toBuffer(uncleHash) : KECCAK256_RLP_ARRAY,
coinbase ? checkBufferLength(toBuffer(coinbase), 20) : zeros(20),
Expand All @@ -83,7 +83,7 @@ export class Header {
throw new Error('Invalid serialized header input. Must be array')
}

return Header.fromValuesArray(values, opts)
return BlockHeader.fromValuesArray(values, opts)
}

public static fromValuesArray(values: Buffer[], opts: BlockOptions) {
Expand All @@ -108,7 +108,7 @@ export class Header {
mixHash,
nonce,
] = values
return new Header(
return new BlockHeader(
parentHash,
uncleHash,
coinbase,
Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Block } from './block'
export { Header } from './header'
export { BlockHeader } from './header'
export * from './types'
12 changes: 6 additions & 6 deletions packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as tape from 'tape'
import Common from '@ethereumjs/common'
import { rlp, toBuffer, zeros, KECCAK256_RLP, KECCAK256_RLP_ARRAY } from 'ethereumjs-util'
import { Header } from '../src/header'
import { BlockHeader } from '../src/header'
//import { Block } from '../src/block'

tape('[Block]: Header functions', function (t) {
Expand All @@ -24,7 +24,7 @@ tape('[Block]: Header functions', function (t) {
st.deepEqual(header.nonce, zeros(8))
}

let header = Header.fromHeaderData({})
let header = BlockHeader.fromHeaderData({})
compareDefaultHeader(st, header)

/*const block = new Block()
Expand Down Expand Up @@ -55,16 +55,16 @@ tape('[Block]: Header functions', function (t) {
})*/

t.test('should test isGenesis', function (st) {
let header = Header.fromHeaderData({})
let header = BlockHeader.fromHeaderData({})
st.equal(header.isGenesis(), false)
header = Header.fromHeaderData({}, { initWithGenesisHeader: true })
header = BlockHeader.fromHeaderData({}, { initWithGenesisHeader: true })
st.equal(header.isGenesis(), true)
st.end()
})

const testDataGenesis = require('./testdata/genesishashestest.json').test
t.test('should test genesis hashes (mainnet default)', function (st) {
const header = Header.fromHeaderData({}, { initWithGenesisHeader: true })
const header = BlockHeader.fromHeaderData({}, { initWithGenesisHeader: true })
st.strictEqual(
header.hash().toString('hex'),
testDataGenesis.genesis_hash,
Expand All @@ -75,7 +75,7 @@ tape('[Block]: Header functions', function (t) {

t.test('should test genesis parameters (ropsten)', function (st) {
const common = new Common({ chain: 'ropsten', hardfork: 'chainstart' })
const genesisHeader = Header.fromHeaderData({}, { common, initWithGenesisHeader: true })
const genesisHeader = BlockHeader.fromHeaderData({}, { common, initWithGenesisHeader: true })
const ropstenStateRoot = '0x217b0bbcfb72e2d57e28f33cb361b9983513177755dc3f33ce3e7022ed62b77b'
st.strictEqual(
genesisHeader.stateRoot.toString('hex'),
Expand Down