Skip to content

Commit

Permalink
add fn to printout depency cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
segfaultdoc committed Nov 30, 2024
1 parent 4dde636 commit 6d34bc2
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ solana-borsh = { path = "sdk/borsh", version = "=2.2.0" }
solana-bpf-loader-program = { path = "programs/bpf_loader", version = "=2.2.0" }
solana-bucket-map = { path = "bucket_map", version = "=2.2.0" }
solana-builtins-default-costs = { path = "builtins-default-costs", version = "=2.2.0" }
solana-bundle = { path = "bundle-execution", version = "=2.2.0" }
solana-bundle-execution = { path = "bundle-execution", version = "=2.2.0" }
agave-cargo-registry = { path = "cargo-registry", version = "=2.2.0" }
solana-clap-utils = { path = "clap-utils", version = "=2.2.0" }
solana-clap-v3-utils = { path = "clap-v3-utils", version = "=2.2.0" }
Expand Down
8 changes: 4 additions & 4 deletions bundle-execution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "solana-bundle"
description = "Library related to handling bundles"
documentation = "https://docs.rs/solana-bundle"
name = "solana-bundle-execution"
description = "Library related to executing bundles"
documentation = "https://docs.rs/solana-bundle-execution"
readme = "../README.md"
version = { workspace = true }
authors = { workspace = true }
Expand Down Expand Up @@ -35,4 +35,4 @@ solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }

[lib]
crate-type = ["lib"]
name = "solana_bundle"
name = "solana_bundle_execution"
61 changes: 48 additions & 13 deletions ci/order-crates-for-publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,51 @@ def should_add(package, dependency, wrong_self_dev_dependencies):
and not is_path_dev_dep(dependency)
)

def find_cycle(graph):
"""
Find a cycle in the dependency graph using Tarjan's algorithm.
Returns the first cycle found as a list, or None if no cycles exist.
"""
def dfs(node, path, visited):
if node in path:
cycle_start = path.index(node)
return path[cycle_start:] + [node]

if node in visited:
return None

visited.add(node)
path.append(node)

for neighbor in graph[node]:
if neighbor not in graph:
continue
cycle = dfs(neighbor, path, visited)
if cycle:
return cycle

path.pop()
return None

visited = set()
for start in graph:
if start not in visited:
cycle = dfs(start, [], visited)
if cycle:
return cycle
return None

def get_packages():
metadata = load_metadata()

manifest_path = dict()

# Build dictionary of packages and their immediate solana-only dependencies
dependency_graph = dict()
wrong_self_dev_dependencies = list()

for pkg in metadata['packages']:
manifest_path[pkg['name']] = pkg['manifest_path'];
manifest_path[pkg['name']] = pkg['manifest_path']
dependency_graph[pkg['name']] = [
x['name'] for x in pkg['dependencies'] if should_add(pkg, x, wrong_self_dev_dependencies)
];
]

# Check for direct circular dependencies
circular_dependencies = set()
Expand All @@ -118,21 +149,26 @@ def get_packages():
sys.stderr.write('Error: Circular dependency: {}\n'.format(dependency))
for dependency in wrong_self_dev_dependencies:
sys.stderr.write('Error: wrong dev-context-only-utils circular dependency. try: ' +
'{} = {{ path = ".", features = {} }}\n'
.format(dependency['name'], json.dumps(dependency['features']))
)
'{} = {{ path = ".", features = {} }}\n'
.format(dependency['name'], json.dumps(dependency['features']))
)

if len(circular_dependencies) != 0 or len(wrong_self_dev_dependencies) != 0:
sys.exit(1)

# Order dependencies
sorted_dependency_graph = []
max_iterations = pow(len(dependency_graph),2)
max_iterations = pow(len(dependency_graph), 2)
while dependency_graph:
deleted_packages = []
if max_iterations == 0:
# One day be more helpful and find the actual cycle for the user...
sys.exit('Error: Circular dependency suspected between these packages: \n {}\n'.format('\n '.join(dependency_graph.keys())))
# Find the actual cycle
cycle = find_cycle(dependency_graph)
if cycle:
cycle_str = ' -> '.join(cycle)
sys.exit('Error: Circular dependency detected:\n{}\n'.format(cycle_str))
else:
sys.exit('Error: Dependency resolution failed but no cycle found. This might indicate a bug.')

max_iterations -= 1

Expand All @@ -146,8 +182,7 @@ def get_packages():
deleted_packages.append(package)
sorted_dependency_graph.append((package, manifest_path[package]))

dependency_graph = {p: d for p, d in dependency_graph.items() if not p in deleted_packages }

dependency_graph = {p: d for p, d in dependency_graph.items() if not p in deleted_packages}

return sorted_dependency_graph

Expand Down
4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ serde_derive = { workspace = true }
solana-accounts-db = { workspace = true }
solana-bloom = { workspace = true }
solana-builtins-default-costs = { workspace = true }
solana-bundle = { workspace = true }
solana-bundle-execution = { workspace = true }
solana-client = { workspace = true }
solana-compute-budget = { workspace = true }
solana-connection-cache = { workspace = true }
Expand Down Expand Up @@ -114,7 +114,7 @@ serde_json = { workspace = true }
serial_test = { workspace = true }
solana-accounts-db = { workspace = true }
## See order-crates-for-publishing.py for using this unusual `path = "."`
solana-bundle = { workspace = true }
solana-bundle-execution = { workspace = true }
solana-core = { path = ".", features = ["dev-context-only-utils"] }
solana-cost-model = { workspace = true, features = ["dev-context-only-utils"] }
solana-ledger = { workspace = true, features = ["dev-context-only-utils"] }
Expand Down
7 changes: 4 additions & 3 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc-client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
solana-account-decoder-client-types = { workspace = true }
solana-bundle-execution = { workspace = true }
solana-inline-spl = { workspace = true }
solana-sdk = { workspace = true }
solana-transaction-status-client-types = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde_json = { workspace = true }
soketto = { workspace = true }
solana-account-decoder = { workspace = true }
solana-accounts-db = { workspace = true }
solana-bundle = { workspace = true }
solana-bundle-execution = { workspace = true }
solana-client = { workspace = true }
solana-entry = { workspace = true }
solana-faucet = { workspace = true }
Expand Down

0 comments on commit 6d34bc2

Please sign in to comment.