diff --git a/lint/ast-grep/fixtures/bad/follow_live_vs_max_outbound.rs b/lint/ast-grep/fixtures/bad/follow_live_vs_max_outbound.rs new file mode 100644 index 000000000..eca20b7ce --- /dev/null +++ b/lint/ast-grep/fixtures/bad/follow_live_vs_max_outbound.rs @@ -0,0 +1,3 @@ +fn stale_follow_needs_room(follow_live: usize, max_outbound: usize) -> bool { + false // cap deleted - unbounded follow_live +} diff --git a/lint/ast-grep/fixtures/bad/held_bodies_cap.rs b/lint/ast-grep/fixtures/bad/held_bodies_cap.rs new file mode 100644 index 000000000..0e6bfb422 --- /dev/null +++ b/lint/ast-grep/fixtures/bad/held_bodies_cap.rs @@ -0,0 +1,4 @@ +struct HeldBodies; +impl HeldBodies { + const CAP: usize = 1024; +} diff --git a/lint/ast-grep/fixtures/bad/pending_blocks_cap.rs b/lint/ast-grep/fixtures/bad/pending_blocks_cap.rs new file mode 100644 index 000000000..69546594f --- /dev/null +++ b/lint/ast-grep/fixtures/bad/pending_blocks_cap.rs @@ -0,0 +1,2 @@ +// should fail - cap changed from 128 +const MAX_PENDING_BLOCKS: usize = 1024; diff --git a/lint/ast-grep/fixtures/bad/serve_blocks_cap.rs b/lint/ast-grep/fixtures/bad/serve_blocks_cap.rs new file mode 100644 index 000000000..8d33f3d94 --- /dev/null +++ b/lint/ast-grep/fixtures/bad/serve_blocks_cap.rs @@ -0,0 +1 @@ +const MAX_SERVE_BLOCKS: usize = 32; diff --git a/lint/ast-grep/fixtures/good/follow_live_vs_max_outbound.rs b/lint/ast-grep/fixtures/good/follow_live_vs_max_outbound.rs new file mode 100644 index 000000000..e8cfcfebd --- /dev/null +++ b/lint/ast-grep/fixtures/good/follow_live_vs_max_outbound.rs @@ -0,0 +1,3 @@ +fn stale_follow_needs_room(follow_live: usize, max_outbound: usize) -> bool { + follow_live >= max_outbound.max(1) +} diff --git a/lint/ast-grep/fixtures/good/held_bodies_cap.rs b/lint/ast-grep/fixtures/good/held_bodies_cap.rs new file mode 100644 index 000000000..80baf7376 --- /dev/null +++ b/lint/ast-grep/fixtures/good/held_bodies_cap.rs @@ -0,0 +1,4 @@ +struct HeldBodies; +impl HeldBodies { + const CAP: usize = 320; +} diff --git a/lint/ast-grep/fixtures/good/pending_blocks_cap.rs b/lint/ast-grep/fixtures/good/pending_blocks_cap.rs new file mode 100644 index 000000000..c88f6f693 --- /dev/null +++ b/lint/ast-grep/fixtures/good/pending_blocks_cap.rs @@ -0,0 +1,2 @@ +// should pass - correct cap per docs/ibd-memory.md Q-54 +const MAX_PENDING_BLOCKS: usize = 128; diff --git a/lint/ast-grep/fixtures/good/serve_blocks_cap.rs b/lint/ast-grep/fixtures/good/serve_blocks_cap.rs new file mode 100644 index 000000000..4bf54aac2 --- /dev/null +++ b/lint/ast-grep/fixtures/good/serve_blocks_cap.rs @@ -0,0 +1 @@ +const MAX_SERVE_BLOCKS: usize = 16; diff --git a/lint/ast-grep/rules/follow-live-vs-max-outbound.yml b/lint/ast-grep/rules/follow-live-vs-max-outbound.yml new file mode 100644 index 000000000..04b02c303 --- /dev/null +++ b/lint/ast-grep/rules/follow-live-vs-max-outbound.yml @@ -0,0 +1,9 @@ +id: follow-live-vs-max-outbound +language: rust +severity: error +message: "stale_follow_needs_room must be follow_live >= max_outbound.max(1) - see docs/ibd-memory.md:61 Q-54" +rule: + all: + - pattern: "fn stale_follow_needs_room($$$) -> bool { $$$ }" + - not: + pattern: "fn stale_follow_needs_room($$$) -> bool { $$$ $A >= $B.max(1) $$$ }" diff --git a/lint/ast-grep/rules/held-bodies-cap.yml b/lint/ast-grep/rules/held-bodies-cap.yml new file mode 100644 index 000000000..eae7d84ad --- /dev/null +++ b/lint/ast-grep/rules/held-bodies-cap.yml @@ -0,0 +1,19 @@ +id: held-bodies-cap +language: rust +severity: error +message: "HeldBodies::CAP must be 320 - see docs/ibd-memory.md Q-54" +rule: + all: + - pattern: | + impl HeldBodies { + $$$ + const CAP: $T = $VAL; + $$$ + } + - not: + pattern: | + impl HeldBodies { + $$$ + const CAP: $T = 320; + $$$ + } diff --git a/lint/ast-grep/rules/pending-blocks-cap.yml b/lint/ast-grep/rules/pending-blocks-cap.yml new file mode 100644 index 000000000..c946987af --- /dev/null +++ b/lint/ast-grep/rules/pending-blocks-cap.yml @@ -0,0 +1,9 @@ +id: pending-blocks-cap +language: rust +severity: error +message: "MAX_PENDING_BLOCKS must be 128 - see docs/ibd-memory.md Q-54" +rule: + all: + - pattern: "const MAX_PENDING_BLOCKS: $T = $VAL;" + - not: + pattern: "const MAX_PENDING_BLOCKS: $T = 128;" diff --git a/lint/ast-grep/rules/serve-blocks-cap.yml b/lint/ast-grep/rules/serve-blocks-cap.yml new file mode 100644 index 000000000..ef3a2bf40 --- /dev/null +++ b/lint/ast-grep/rules/serve-blocks-cap.yml @@ -0,0 +1,9 @@ +id: serve-blocks-cap +language: rust +severity: error +message: "MAX_SERVE_BLOCKS must be 16 - see docs/ibd-memory.md Q-54" +rule: + all: + - pattern: "const MAX_SERVE_BLOCKS: $T = $VAL;" + - not: + pattern: "const MAX_SERVE_BLOCKS: $T = 16;"