Skip to content

Commit 03b0758

Browse files
Fix crash while applying bigmap diffs with complex keys (#194)
* Apply diffs by id, initial and dirty af * Tests, docs * Typo * Correct logic, but with wraps * Replace unwraps with copypaste * Lint * remove some copypaste * Docs, optimizations * Refactoring * Ignore missing fields * Refactoring, disable edo tests * CI * Failing tests * Another failing test * Fix naming * asdf-qwer * Tests * Simplify checks, fix hjkl test, structure test data * Preprocess storage schema * Bump just in case * Remove --use-default to fix bigmap type * Cleanup, comments * Process unions in lists * fix list types detector, lint * Lint, docs * lint * Fix bazaar storage, refactoring * new test * fix test * Lint * failing test * Fix last test * Refactoring, docs * Update changelog * Cleanup * Disable integration tests
1 parent e0e48a7 commit 03b0758

40 files changed

+1625
-180
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
66

77
## Fixed
88

9+
* codegen: Fixed generating storage typeclasses with `Union` fields.
10+
* codegen: Fixed preprocessing contract JSONSchema.
911
* index: Fixed processing reindexing reason saved in the database.
1012
* tzkt: Fixed processing operations with default entrypoint and empty parameter.
13+
* tzkt: Fixed crash while recursively applying bigmap diffs to the storage.
14+
15+
## Performance
16+
17+
* tzkt: Increased speed of applying bigmap diffs to operation storage.
1118

1219
## 4.0.0 - 2021-12-24
1320

poetry.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sentry-sdk = "^1.1.0"
4040
sqlparse = "^0.4.1"
4141
tabulate = "^0.8.9"
4242
tortoise-orm = "0.17.8"
43+
typing-inspect = "^0.6.0"
4344

4445
[tool.poetry.dev-dependencies]
4546
black = "^20.8b1"

scripts/init_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#$/bin/bash
2+
cd tests/test_dipdup
3+
for name in "asdf" "qwer" "hjkl" "zxcv" "rewq"
4+
do
5+
dipdup -c $name.yml init
6+
mv $name/types/$name/storage.py types/$name/storage.py
7+
rm -r $name
8+
done

src/dipdup/codegen.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,25 @@
6161
_templates: Dict[str, Template] = {}
6262

6363

64-
def resolve_big_maps(schema: Dict[str, Any]) -> Dict[str, Any]:
64+
def preprocess_storage_jsonschema(schema: Dict[str, Any]) -> Dict[str, Any]:
6565
"""Preprocess bigmaps in JSONSchema. Those are unions as could be pointers.
6666
We resolve bigmaps from diffs so no need to include int in type signature."""
67+
if not isinstance(schema, dict):
68+
return schema
6769
if 'properties' in schema:
6870
return {
6971
**schema,
70-
'properties': {prop: resolve_big_maps(sub_schema) for prop, sub_schema in schema['properties'].items()},
72+
'properties': {prop: preprocess_storage_jsonschema(sub_schema) for prop, sub_schema in schema['properties'].items()},
73+
}
74+
elif 'items' in schema:
75+
return {
76+
**schema,
77+
'items': preprocess_storage_jsonschema(schema['items']),
78+
}
79+
elif 'additionalProperties' in schema:
80+
return {
81+
**schema,
82+
'additionalProperties': preprocess_storage_jsonschema(schema['additionalProperties']),
7183
}
7284
elif schema.get('$comment') == 'big_map':
7385
return schema['oneOf'][1]
@@ -165,8 +177,8 @@ async def fetch_schemas(self) -> None:
165177
mkdir_p(contract_schemas_path)
166178

167179
storage_schema_path = join(contract_schemas_path, 'storage.json')
180+
storage_schema = preprocess_storage_jsonschema(contract_schemas['storageSchema'])
168181

169-
storage_schema = resolve_big_maps(contract_schemas['storageSchema'])
170182
write(storage_schema_path, json.dumps(storage_schema, indent=4, sort_keys=True))
171183

172184
if not isinstance(operation_pattern_config, OperationHandlerTransactionPatternConfig):
@@ -279,7 +291,6 @@ async def generate_types(self, overwrite_types: bool = False) -> None:
279291
'--class-name',
280292
name.lstrip('_'),
281293
'--disable-timestamp',
282-
'--use-default',
283294
]
284295
self._logger.debug(' '.join(args))
285296
subprocess.run(args, check=True)

0 commit comments

Comments
 (0)