Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3540 from trufflesuite/develop
Browse files Browse the repository at this point in the history
Release v7.4.1
  • Loading branch information
MicaiahReid committed Aug 15, 2022
2 parents 4bac7d8 + 2cdf9bd commit 57a2439
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ jobs:
echo "Bundle size is $([[ "$size" -lt 99000000 ]] && echo "ok" || echo "not ok")" &&
test "$size" -lt 99000000
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
# use a fake infura key for the bundle size check so this test will
# run successfully on external contributor Pull Requests
INFURA_KEY: "badc0de0deadc0debadc0de0deadc0de"
10 changes: 5 additions & 5 deletions src/chains/ethereum/address/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("@ganache/ethereum-address", () => {
const address = new Address("0x1");
const stringifiedAddress = address.toString();

assert.equal(
assert.strictEqual(
stringifiedAddress,
"0x0000000000000000000000000000000000000001"
);
Expand All @@ -17,14 +17,14 @@ describe("@ganache/ethereum-address", () => {
const address = new Address("0x1");
const stringifiedAddress = address.toString(1);

assert.equal(stringifiedAddress, "0x01");
assert.strictEqual(stringifiedAddress, "0x01");
});

it("should stringify a 20 byte address string", () => {
const address = new Address("0x2104859394604359378433865360947116707876");
const stringifiedAddress = address.toString();

assert.equal(
assert.strictEqual(
stringifiedAddress,
"0x2104859394604359378433865360947116707876"
);
Expand All @@ -33,7 +33,7 @@ describe("@ganache/ethereum-address", () => {
it("should pad an address to 20 bytes when called as static function", () => {
const stringifiedAddress = Address.toString("0x1");

assert.equal(
assert.strictEqual(
stringifiedAddress,
"0x0000000000000000000000000000000000000001"
);
Expand All @@ -54,7 +54,7 @@ describe("@ganache/ethereum-address", () => {
const address = new Address("0x2104859394604359378433865360947116707876");
const stringifiedAddress = address.toString(1);

assert.equal(stringifiedAddress, "0x21");
assert.strictEqual(stringifiedAddress, "0x21");
});

it("should convert a 20 byte address to a buffer", () => {
Expand Down
4 changes: 0 additions & 4 deletions src/chains/ethereum/ethereum/RPC-METHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,6 @@ Returns: An Array with the following elements:
2. `DATA`, 32 Bytes - the seed hash used for the DAG.
3. `DATA`, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.

##### Arguments

- `filterId: QUANTITY` : A filter id.

##### Returns

`Promise<[] | [string, string, string]>` : The hash of the current block, the seedHash, and the boundary condition to be met ("target").
Expand Down
15 changes: 8 additions & 7 deletions src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export default class EthereumApi implements Api {
async evm_setAccountNonce(address: DATA, nonce: QUANTITY) {
// TODO: the effect of this function could happen during a block mine operation, which would cause all sorts of
// issues. We need to figure out a good way of timing this.
// Issue: https://github.com/trufflesuite/ganache/issues/1646
const buffer = Address.from(address).toBuffer();
const blockchain = this.#blockchain;
const stateManager = blockchain.vm.stateManager;
Expand Down Expand Up @@ -391,6 +392,7 @@ export default class EthereumApi implements Api {
async evm_setAccountBalance(address: DATA, balance: QUANTITY) {
// TODO: the effect of this function could happen during a block mine operation, which would cause all sorts of
// issues. We need to figure out a good way of timing this.
// Issue: https://github.com/trufflesuite/ganache/issues/1646
const buffer = Address.from(address).toBuffer();
const blockchain = this.#blockchain;
const stateManager = blockchain.vm.stateManager;
Expand Down Expand Up @@ -429,6 +431,7 @@ export default class EthereumApi implements Api {
async evm_setAccountCode(address: DATA, code: DATA) {
// TODO: the effect of this function could happen during a block mine operation, which would cause all sorts of
// issues. We need to figure out a good way of timing this.
// Issue: https://github.com/trufflesuite/ganache/issues/1646
const addressBuffer = Address.from(address).toBuffer();
const codeBuffer = Data.toBuffer(code);
const blockchain = this.#blockchain;
Expand Down Expand Up @@ -477,6 +480,7 @@ export default class EthereumApi implements Api {
async evm_setAccountStorageAt(address: DATA, slot: DATA, value: DATA) {
// TODO: the effect of this function could happen during a block mine operation, which would cause all sorts of
// issues. We need to figure out a good way of timing this.
// Issue: https://github.com/trufflesuite/ganache/issues/1646
const addressBuffer = Address.from(address).toBuffer();
const slotBuffer = Data.toBuffer(slot);
const valueBuffer = Data.toBuffer(value);
Expand Down Expand Up @@ -866,7 +870,6 @@ export default class EthereumApi implements Api {

//#region eth

// TODO: example doesn't return correct value
/**
* Generates and returns an estimate of how much gas is necessary to allow the
* transaction to complete. The transaction will not be added to the
Expand Down Expand Up @@ -1498,15 +1501,14 @@ export default class EthereumApi implements Api {
* 2: `DATA`, 32 Bytes - the seed hash used for the DAG.
* 3: `DATA`, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.
*
* @param filterId - A filter id.
* @returns The hash of the current block, the seedHash, and the boundary condition to be met ("target").
* @example
* ```javascript
* console.log(await provider.send("eth_getWork", ["0x0"] ));
* console.log(await provider.send("eth_getWork", [] ));
* ```
*/
@assertArgLength(1)
async eth_getWork(filterId: QUANTITY) {
@assertArgLength(0)
async eth_getWork() {
return [] as [string, string, string] | [];
}

Expand Down Expand Up @@ -2940,6 +2942,7 @@ export default class EthereumApi implements Api {
}

// TODO: example doesn't return correct value
// Issue: https://github.com/trufflesuite/ganache/issues/3203
/**
* Attempts to replay the transaction as it was executed on the network and
* return storage data given a starting key and max number of entries to return.
Expand Down Expand Up @@ -3015,7 +3018,6 @@ export default class EthereumApi implements Api {
return this.#wallet.addresses;
}

// TODO: example doesn't return correct value
/**
* Generates a new account with private key. Returns the address of the new
* account.
Expand Down Expand Up @@ -3094,7 +3096,6 @@ export default class EthereumApi implements Api {
return this.#wallet.lockAccount(address.toLowerCase());
}

// TODO: example doesn't return correct value
/**
* Unlocks the account for use.
*
Expand Down
5 changes: 4 additions & 1 deletion src/chains/ethereum/ethereum/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {

resume(_threads: number = 1) {
if (!this.#isPaused()) {
console.log("Warning: startMining called when miner was already started");
this.#options.logging.logger.log(
"Warning: startMining called when miner was already started"
);
return;
}

Expand Down Expand Up @@ -1207,6 +1209,7 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
// TODO: gas could go theoretically go over Number.MAX_SAFE_INTEGER.
// (Ganache v2 didn't handle this possibility either, so it hasn't been
// updated yet)
// Issue: https://github.com/trufflesuite/ganache/issues/3473
let gas = 0;
const structLogs: Array<StructLog> = [];
const TraceData = TraceDataFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export default class BlockManager extends Manager<Block> {
async getRawByBlockNumber(blockNumber: Quantity): Promise<Buffer> {
// TODO(perf): make the block's raw fields accessible on latest/earliest/pending so
// we don't have to fetch them from the db each time a block tag is used.
// Issue: https://github.com/trufflesuite/ganache/issues/3481
const fallback = this.#blockchain.fallback;
const numBuf = blockNumber.toBuffer();
return this.getRaw(numBuf).then(block => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class BlockLogManager extends Manager<BlockLogs> {
blockLogsRange.forEach(blockLogs => {
// TODO(perf): this loops over all addresses for every block.
// Maybe make it loop only once?
// Issue: https://github.com/trufflesuite/ganache/issues/3482
if (blockLogs)
filteredBlockLogs.push(...blockLogs.filter(addresses, topics));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EthereumInternalOptions } from "@ganache/ethereum-options";
import { JsonRpcResponse, JsonRpcError } from "@ganache/utils";
import { AbortError } from "@ganache/ethereum-utils";
// TODO: support http2
// Issue: https://github.com/trufflesuite/ganache/issues/3474
import http, { RequestOptions, Agent as HttpAgent } from "http";
import https, { Agent as HttpsAgent } from "https";
import { AbortSignal } from "abort-controller";
Expand Down Expand Up @@ -138,6 +139,7 @@ export class HttpHandler extends BaseHandler implements Handler {
}

// TODO: handle invalid JSON (throws on parse)?
// Issue: https://github.com/trufflesuite/ganache/issues/3475
buffer.then(buffer => {
try {
deferred.resolve({
Expand Down
22 changes: 16 additions & 6 deletions src/chains/ethereum/ethereum/src/forking/handlers/ws-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EthereumInternalOptions } from "@ganache/ethereum-options";
import { AbortError, CodedError } from "@ganache/ethereum-utils";
import { AbortError } from "@ganache/ethereum-utils";
import { AbortSignal } from "abort-controller";
import WebSocket from "ws";
import { Handler } from "../types";
Expand All @@ -23,7 +23,10 @@ export class WsHandler extends BaseHandler implements Handler {
constructor(options: EthereumInternalOptions, abortSignal: AbortSignal) {
super(options, abortSignal);

const { url, origin } = options.fork;
const {
fork: { url, origin },
logging
} = options;

this.connection = new WebSocket(url.toString(), {
origin,
Expand All @@ -40,11 +43,13 @@ export class WsHandler extends BaseHandler implements Handler {
// handler too.
this.connection.binaryType = "nodebuffer";

this.open = this.connect(this.connection);
this.open = this.connect(this.connection, logging);
this.connection.onclose = () => {
// try to connect again...
// Issue: https://github.com/trufflesuite/ganache/issues/3476
// TODO: backoff and eventually fail
this.open = this.connect(this.connection);
// Issue: https://github.com/trufflesuite/ganache/issues/3477
this.open = this.connect(this.connection, logging);
};
this.abortSignal.addEventListener("abort", () => {
this.connection.onclose = null;
Expand Down Expand Up @@ -73,6 +78,7 @@ export class WsHandler extends BaseHandler implements Handler {
}>();

// TODO: timeout an in-flight request after some amount of time
// Issue: https://github.com/trufflesuite/ganache/issues/3478
this.inFlightRequests.set(messageId, deferred);

this.connection.send(`${JSONRPC_PREFIX}${messageId},${key.slice(1)}`);
Expand All @@ -89,6 +95,7 @@ export class WsHandler extends BaseHandler implements Handler {
const raw = event.data as Buffer;

// TODO: handle invalid JSON (throws on parse)?
// Issue: https://github.com/trufflesuite/ganache/issues/3479
const response = JSON.parse(raw) as JsonRpcResponse | JsonRpcError;
const id = response.id;
const prom = this.inFlightRequests.get(id);
Expand All @@ -98,7 +105,10 @@ export class WsHandler extends BaseHandler implements Handler {
}
}

private connect(connection: WebSocket) {
private connect(
connection: WebSocket,
logging: EthereumInternalOptions["logging"]
) {
let open = new Promise((resolve, reject) => {
connection.onopen = resolve;
connection.onerror = reject;
Expand All @@ -109,7 +119,7 @@ export class WsHandler extends BaseHandler implements Handler {
connection.onerror = null;
},
err => {
console.log(err);
logging.logger.log(err);
}
);
return open;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class PersistentCache {

// TODO(perf): we always re-save the targetBlock but could optimize to only
// resave if it is needed.
// Issue: https://github.com/trufflesuite/ganache/issues/3485
atomicBatch.put(targetBlock.key, targetBlock.serialize());

await atomicBatch.write();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { AbortSignal } from "abort-controller";
import Semaphore from "semaphore";
import { LimitCounter } from "./limit-counter";

type PromiseFn<T> = (
...args: unknown[]
) => Promise<{
type PromiseFn<T> = (...args: unknown[]) => Promise<{
response: { result: any } | { error: { message: string; code: number } };
raw: T;
}>;
Expand Down Expand Up @@ -234,6 +232,7 @@ export default class RateLimiter {
// a LIMIT_EXCEEDED error behave, otherwise we'll just send ALL
// requests back to Infura simultaneously after their initial 30
// backoff_seconds have elapsed.
// Issue: https://github.com/trufflesuite/ganache/issues/3480
//
// When we are *not* self-rate limited (meaning fork.rps isn't set)
// we need to be able to go at full speed until we are, and THEN we
Expand Down
2 changes: 2 additions & 0 deletions src/chains/ethereum/ethereum/src/forking/trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class ForkTrie extends GanacheTrie {
// checking the database itself
// TODO(perf): there is probably a better/faster way of doing this for the
// common case.
// Issue: https://github.com/trufflesuite/ganache/issues/3483
const checkpoints = this.metadata.checkpoints;
for (let i = checkpoints.length - 1; i >= 0; i--) {
for (let [encodedKeyStr, value] of checkpoints[i].keyValueMap.entries()) {
Expand All @@ -137,6 +138,7 @@ export class ForkTrie extends GanacheTrie {
// TODO(perf): this is just going to be slow once we get lots of keys
// because it just checks every single key we've ever deleted (before this
// one).
// Issue: https://github.com/trufflesuite/ganache/issues/3484
const stream = this.metadata._leveldb.createReadStream({
lte: this.createDelKey(key),
reverse: true
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/tests/api/eth/eth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("api", () => {

describe("eth_getWork", () => {
it("should get compilers list", async () => {
const result = await provider.send("eth_getWork", ["0x0"]);
const result = await provider.send("eth_getWork");
assert.deepStrictEqual(result, []);
});
});
Expand Down
9 changes: 6 additions & 3 deletions src/chains/ethereum/ethereum/tests/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ describe("blockchain", async () => {
try {
const blockNumber = block.header.number.toString();
const expectedBlockNumber = startingBlockNumber + i + 1;
assert.equal(blockNumber, `0x${expectedBlockNumber.toString(16)}`);
assert.equal(transactions.length, 1);
assert.strictEqual(
blockNumber,
`0x${expectedBlockNumber.toString(16)}`
);
assert.strictEqual(transactions.length, 1);

const transaction = transactions[0];
assert.equal(
assert.strictEqual(
transaction.hash.toString(),
transactionHashes[i].toString()
);
Expand Down
4 changes: 2 additions & 2 deletions src/chains/ethereum/options/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("EthereumOptionsConfig", () => {
const options = EthereumOptionsConfig.normalize({
wallet: { totalAccounts: 7 }
});
assert.equal(options.wallet.totalAccounts, 7);
assert.strictEqual(options.wallet.totalAccounts, 7);
});
it("throws an error when an option conflict is found", () => {
assert.throws(() => {
Expand All @@ -55,7 +55,7 @@ describe("EthereumOptionsConfig", () => {
it("accepts some legacy input formats", () => {
const seed = "from their voids, cry to the dolphined sea";
const options = EthereumOptionsConfig.normalize({ seed } as Object);
assert.equal(options.wallet.seed, seed);
assert.strictEqual(options.wallet.seed, seed);
});
it("errors if there is a conflict with legacy inputs", () => {
const seed = "I ate three cookies";
Expand Down
1 change: 1 addition & 0 deletions src/chains/ethereum/transaction/src/base-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const calculateIntrinsicGas = (
// Make sure we don't exceed uint64 for all data combinations.
// TODO: make sure these upper-bound checks are safe to remove, then
// remove if so.
// Issue: https://github.com/trufflesuite/ganache/issues/3486
// NOTE: This is an upper-bounds limit ported from geth that doesn't
// make sense for Ethereum, as exceeding the upper bound would require
// something like 200+ Petabytes of data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
public maxFeePerGas: Quantity;
public accessList: AccessListBuffer;
public accessListJSON: AccessList;
public accessListDataFee: bigint;
public type: Quantity = Quantity.from("0x2");

public constructor(
Expand All @@ -70,6 +71,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
const accessListData = AccessLists.getAccessListData(data[8]);
this.accessList = accessListData.accessList;
this.accessListJSON = accessListData.AccessListJSON;
this.accessListDataFee = accessListData.dataFeeEIP2930;
this.v = Quantity.from(data[9]);
this.r = Quantity.from(data[10]);
this.s = Quantity.from(data[11]);
Expand Down Expand Up @@ -107,6 +109,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
const accessListData = AccessLists.getAccessListData(data.accessList);
this.accessList = accessListData.accessList;
this.accessListJSON = accessListData.AccessListJSON;
this.accessListDataFee = accessListData.dataFeeEIP2930;
this.validateAndSetSignature(data);
}
}
Expand Down Expand Up @@ -177,7 +180,7 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
*/
getBaseFee: () => {
const fee = this.calculateIntrinsicGas();
return new BN(Quantity.toBuffer(fee));
return new BN(Quantity.toBuffer(fee + this.accessListDataFee));
},
getUpfrontCost: (baseFee: BN = new BN(0)) => {
const { gas, maxPriorityFeePerGas, maxFeePerGas, value } = this;
Expand Down
Loading

0 comments on commit 57a2439

Please sign in to comment.