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

Commit

Permalink
Eliminate indicateUnknown option; add error handling; simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Jul 14, 2022
1 parent d9fc197 commit 17ba791
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
30 changes: 18 additions & 12 deletions packages/debugger/lib/data/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,22 @@ function* variablesAndMappingsSaga() {

function* decodeMappingKeySaga(indexDefinition, keyDefinition) {
//something of a HACK -- cleans any out-of-range booleans
//resulting from the main mapping key decoding loop
const indexValue = yield* decodeMappingKeyCore(
indexDefinition,
keyDefinition
);
//resulting from the main mapping key decoding loop,
//and also filters out errors
let indexValue = yield* decodeMappingKeyCore(indexDefinition, keyDefinition);
if (indexValue) {
indexValue = Codec.Conversion.cleanBool(indexValue);
switch (indexValue.kind) {
case "value":
return indexValue;
case "error":
//if it's still an error after cleaning booleans...
//let's not store it as a mapping key
return null;
}
} else {
return indexValue;
}
return indexValue ? Codec.Conversion.cleanBool(indexValue) : indexValue;
}

Expand Down Expand Up @@ -1028,12 +1039,7 @@ function fetchBasePath(
return null;
}

export function* decode(
definition,
ref,
compilationId,
indicateUnknown = false
) {
export function* decode(definition, ref, compilationId) {
const userDefinedTypes = yield select(data.views.userDefinedTypes);
const state = yield select(data.current.state);
const mappingKeys = yield select(data.views.mappingKeys);
Expand Down Expand Up @@ -1071,7 +1077,7 @@ export function* decode(
let response;
switch (request.type) {
case "storage":
response = yield* evm.requestStorage(request.slot, indicateUnknown);
response = yield* evm.requestStorage(request.slot);
break;
case "code":
response = yield* evm.requestCode(request.address);
Expand Down
17 changes: 4 additions & 13 deletions packages/debugger/lib/evm/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function* recordStorage(address, slot, word) {
//go away on a reset! Yes, this is a little weird, but we
//decided this is OK for now
export function* requestCode(address) {
const NO_CODE = new Uint8Array(); //empty array
const blockNumber = (yield select(
evm.transaction.globals.block
)).number.toString();
Expand All @@ -70,12 +69,8 @@ export function* requestCode(address) {
if (address in instances) {
//because this function is used by data, we return a Uint8Array
return Codec.Conversion.toBytes(instances[address].binary);
} else if (address === Codec.Evm.Utils.ZERO_ADDRESS) {
//HACK: to avoid displaying the zero address to the user as an
//affected address just because they decoded a contract or external
//function variable that hadn't been initialized yet, we give the
//zero address's codelessness its own private cache :P
return NO_CODE;
//former special case here for zero address is now gone since it's
//now covered by this case
} else {
//I don't want to write a new web3 saga, so let's just use
//obtainBinaries with a one-element array
Expand All @@ -89,7 +84,7 @@ export function* requestCode(address) {

//NOTE: just like requestCode, this can also add to the codex!
//yes, this is also weird.
export function* requestStorage(slot, indicateUnknown) {
export function* requestStorage(slot) {
//slot is a BN here
const currentStorage = yield select(evm.current.codex.storage);
const slotAsHex = Codec.Conversion.toHexString(slot).slice(2); //remove 0x prefix
Expand All @@ -106,13 +101,9 @@ export function* requestStorage(slot, indicateUnknown) {
const word = yield* web3.obtainStorage(address, slot, blockHash, txIndex);
yield* recordStorage(address, slot, word);
return Codec.Conversion.toBytes(word);
} else if (indicateUnknown) {
} else {
//indicates to codec this storage is unknown
return null;
} else {
const ZERO_WORD = new Uint8Array(Codec.Evm.Utils.WORD_SIZE); //automatically filled with zeroes
return ZERO_WORD; //if we weren't told to indicate unknowns, and
//storage lookup is turned off, we assume anything unknown is zero
}
}

Expand Down
17 changes: 4 additions & 13 deletions packages/debugger/lib/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,7 @@ export default class Session {
return true;
}

/**
* see variables() for supported options
*/
async variable(name, options) {
async variable(name) {
const definitions = this.view(data.current.identifiers.definitions);
const refs = this.view(data.current.identifiers.refs);
const compilationId = this.view(data.current.compilationId);
Expand All @@ -507,16 +504,11 @@ export default class Session {
dataSagas.decode,
definitions[name],
refs[name],
compilationId,
(options || {}).indicateUnknown
compilationId
);
}

/**
* only current option is indicateUnknown, which causes unknown storage
* to yield a StorageNotSuppliedError instead of zero
*/
async variables(options) {
async variables() {
if (!this.view(session.status.loaded)) {
return {};
}
Expand All @@ -530,8 +522,7 @@ export default class Session {
dataSagas.decode,
definitions[identifier],
ref,
compilationId,
(options || {}).indicateUnknown
compilationId
);
}
}
Expand Down

0 comments on commit 17ba791

Please sign in to comment.