Skip to content

Commit

Permalink
Fix v2 queries missing addresses for transactions, improve logging (#281
Browse files Browse the repository at this point in the history
)

* Fix v2 queries missing addresses for transactions, improve logging

* Update changelog
  • Loading branch information
stwiname authored Apr 22, 2024
1 parent 4c47e88 commit 88434cc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Dictionary v2 transactions query not including address (#281)

## [4.1.1] - 2024-04-16
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EthereumApiService } from '../../ethereum';
import { EthDictionaryV1 } from './v1';
import { EthDictionaryV2 } from './v2';

const logger = getLogger('eth-dictionary');
const logger = getLogger('dictionary');

@Injectable()
export class EthDictionaryService extends DictionaryService<
Expand Down Expand Up @@ -69,6 +69,9 @@ export class EthDictionaryService extends DictionaryService<
}
}
}
logger.debug(
`Dictionary versions, v1: ${dictionariesV1.length}, v2: ${dictionariesV2.length}`,
);
// v2 should be prioritised
this.init([...dictionariesV2, ...dictionariesV1]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/indexer/dictionary/v1/ethDictionaryV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ethFilterDs } from '../utils';
const CHAIN_ALIASES_URL =
'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';

const logger = getLogger('eth-dictionary v1');
const logger = getLogger('dictionary-v1');

export function appendDsOptions(
dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],
Expand Down
35 changes: 35 additions & 0 deletions packages/node/src/indexer/dictionary/v2/ethDictionaryV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,40 @@ describe('buildDictionaryV2QueryEntry', () => {
});
});

it('Build filter tx filter', () => {
const ds: SubqlRuntimeDatasource = {
kind: EthereumDatasourceKind.Runtime,
assets: new Map(),
options: {
abi: 'erc20',
address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
},
startBlock: 1,
mapping: {
file: '',
handlers: [
{
handler: 'handleTx',
kind: EthereumHandlerKind.Call,
filter: {
function: 'setminimumStakingAmount(uint256 amount)',
},
},
],
},
};
const result = buildDictionaryV2QueryEntry([ds]);

expect(result).toEqual({
transactions: [
{
to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],
data: ['0x7ef9ea98'],
},
],
});
});

it('build query entries for multiple ds', () => {
const ds: SubqlRuntimeDatasource[] = [
{
Expand Down Expand Up @@ -473,6 +507,7 @@ describe('buildDictionaryV2QueryEntry', () => {
transactions: [
{
from: ['mockaddress'],
to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],
data: ['0x7ef9ea98'],
},
],
Expand Down
27 changes: 18 additions & 9 deletions packages/node/src/indexer/dictionary/v2/ethDictionaryV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { rawBlockToEthBlock } from './utils';

const MIN_FETCH_LIMIT = 200;

const logger = getLogger('eth-dictionary-v2');
const logger = getLogger('dictionary-v2');

function extractOptionAddresses(
dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],
Expand Down Expand Up @@ -77,18 +77,27 @@ function callFilterToDictionaryCondition(
if (filter.from) {
fromArray.push(filter.from.toLowerCase());
}

const assignTo = (value: string | null | undefined) => {
if (value === null) {
toArray.push(null);
} else if (value !== undefined) {
toArray.push(value.toLowerCase());
}
};

const optionsAddresses = extractOptionAddresses(dsOptions);
if (!optionsAddresses.length) {
if (filter.to) {
toArray.push(filter.to.toLowerCase());
} else if (filter.to === null) {
toArray.push(null); //TODO, is this correct?
assignTo(filter.to);
} else {
if (filter.to || filter.to === null) {
logger.warn(
`TransactionFilter 'to' conflicts with 'address' in data source options, using data source option`,
);
}
} else if (!!optionsAddresses.length && (filter.to || filter.to === null)) {
logger.warn(
`TransactionFilter 'to' conflict with 'address' in data source options`,
);
optionsAddresses.forEach(assignTo);
}

if (filter.function) {
funcArray.push(functionToSighash(filter.function));
}
Expand Down

0 comments on commit 88434cc

Please sign in to comment.