-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Motivation Currently, dirty files discovery is not going deep enough into the graph, thus it often fails to discover all files that have dirty imports of some depth > 1. In worst case we may only recompile directly changed files and files directly importing them. This PR changes this, so all files that have dirty files at some depth of their imports are marked as dirty. This should solve a lot of weird issues with verification because it is very simple to occur such bug and it can result in, for example, script having and deploying outdated bytecode of contract which does not match the actual artifact. ## Solution If we would consider that problem as a graph theory problem, than we are dealing with oriented graph of `N` nodes representing files and `M` oriented edges between them representing imports. Some of `N` nodes are marked as dirty initially and we want to mark as dirty all nodes from which a path exists to any of the dirty nodes. Before the fix, the incorrect solution complexity was around `O(M)`, so I didn't want to increase it too much. One possible solution without much changes to code could be to run deeper recursion from each node and try to reach dirty node from it. However, such solution would have a complexity of `O(N*M)` in worst case. The solution I've implemented is working by precomputing `rev_edges` to store reversed edges, thus simplifying the problem to just finding all nodes that are reachable from the dirty ones in the reversed graph. The solution works by running DFS from all nodes that are known to be dirty in the beginning and keeping track of visited (dirty) nodes, to avoid visiting the same node twice. The complexity of such approach is `O(M)` in the worst case because we never use the same edge twice. --------- Co-authored-by: Enrique <hi@enriqueortiz.dev>
- Loading branch information
Showing
3 changed files
with
107 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters