Log RLP failures with full input
This commit is contained in:
@@ -453,7 +453,7 @@ export default class Trie implements TrieDb {
|
||||
}
|
||||
}
|
||||
|
||||
l.log(() => ['newNode', newNode]);
|
||||
// l.debug(() => ['newNode', newNode]);
|
||||
|
||||
if (commonPrefix.length) {
|
||||
return [
|
||||
|
||||
@@ -3,17 +3,24 @@
|
||||
// of the MPL-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import assert from '@polkadot/util/assert';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
|
||||
import internalDecode from './decode';
|
||||
|
||||
export default function decoder (input?: Uint8Array): Uint8Array | Array<any> {
|
||||
if (!input || input.length === 0) {
|
||||
return new Uint8Array([]);
|
||||
try {
|
||||
if (!input || input.length === 0) {
|
||||
return new Uint8Array([]);
|
||||
}
|
||||
|
||||
const { decoded, remainder } = internalDecode(input);
|
||||
|
||||
assert(remainder.length === 0, 'invalid remainder');
|
||||
|
||||
return decoded;
|
||||
} catch (error) {
|
||||
console.error(`RLP failed on input ${u8aToHex(input)}`);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const { decoded, remainder } = internalDecode(input);
|
||||
|
||||
assert(remainder.length === 0, 'invalid remainder');
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function decodeListLong (decode: DecodeFunc, input: Uint8Array):
|
||||
|
||||
let innerRemainder = input.slice(llength, totalLength);
|
||||
|
||||
assert(innerRemainder.length > 0, 'invalid rlp, List has a invalid length');
|
||||
assert(innerRemainder.length > 0, 'invalid rlp, list has a invalid length');
|
||||
|
||||
while (innerRemainder.length) {
|
||||
const d = decode(innerRemainder);
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function decodeNumber (decode: DecodeFunc, input: Uint8Array): De
|
||||
const length = safeParseInt(input.slice(1, llength));
|
||||
const decoded = input.slice(llength, length + llength);
|
||||
|
||||
assert(decoded.length === length, 'invalid RLP');
|
||||
assert(decoded.length === length, `invalid rlp, expected length ${length}, found ${decoded.length}`);
|
||||
|
||||
return {
|
||||
decoded,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import assert from '@polkadot/util/assert';
|
||||
|
||||
export default function safeParseInt (input: Uint8Array): number {
|
||||
assert(input[0] > 0, 'invalid RLP: extra zeros');
|
||||
assert(input[0] > 0, 'invalid rlp, extra zeros found');
|
||||
|
||||
return input.reduce((result, value) => (result * 256) + value, 0);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function decodeString (decode: DecodeFunc, input: Uint8Array): De
|
||||
decoded = input.slice(1, length);
|
||||
}
|
||||
|
||||
assert(!(length === 2 && decoded[0] < 0x80), 'invalid rlp encoding: byte must be less 0x80');
|
||||
assert(!(length === 2 && decoded[0] < 0x80), 'invalid rlp, byte must be less 0x80');
|
||||
|
||||
return {
|
||||
decoded,
|
||||
|
||||
Reference in New Issue
Block a user