Skip to content

Rust: Make statics safe (2/3)#4390

Merged
eljobe merged 5 commits intomasterfrom
pmikolajczyk/nit-4432-statics-2
Feb 17, 2026
Merged

Rust: Make statics safe (2/3)#4390
eljobe merged 5 commits intomasterfrom
pmikolajczyk/nit-4432-statics-2

Conversation

@pmikolajczyk41
Copy link
Copy Markdown
Member

@pmikolajczyk41 pmikolajczyk41 commented Feb 16, 2026

The user-test mock lib used a few unsafe mutable statics, including ARGS, OUTS and LOGS.

Changes:

  • Gathered them all into a common struct GlobalState
  • Created static ref GLOBAL_STATE: Mutex<GlobalState> using lazy_static!. This decision (to use lazy_static instead of thread_local and Mutex instead of RefCell) was made only for consistency with the adjacent code.
  • Introduced minor changes to the UserHost trait (nothing critical). Other implementors were adjusted accordingly:
    • The args getter works on Cow , to support working with both borrowed and owned data (we cannot borrow safely the args field from the static GLOBAL_STATE as we did for the static var ARGS before, so we just copy the data).
    • The outs method was used as both getter and setter fn outs(&mut self) -> &mut Vec<u8>. It was split into getter and setter. The getter now uses Cow, for the same reason as above.

part of NIT-4432

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.15%. Comparing base (f069766) to head (2bc9c05).
⚠️ Report is 16 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4390      +/-   ##
==========================================
- Coverage   33.22%   33.15%   -0.07%     
==========================================
  Files         489      489              
  Lines       58064    58064              
==========================================
- Hits        19290    19252      -38     
- Misses      35385    35468      +83     
+ Partials     3389     3344      -45     

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 16, 2026

❌ 10 Tests Failed:

Tests completed Failed Passed Skipped
4266 10 4256 0
View the top 3 failed tests by shortest run time
TestDataStreaming_PositiveScenario/Many_senders,_long_messages
Stack Traces | 0.110s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
        github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic.func1()
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:230 +0x19b
        created by github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic in goroutine 221
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:223 +0x85
        
    protocol_test.go:230: �[31;1m [] too much time has elapsed since request was signed �[0;0m
WARN [02-17|11:01:25.103] Served datastreaming_start               conn=127.0.0.1:42688 reqid=4 duration="120.045µs" err="too much time has elapsed since request was signed"
INFO [02-17|11:01:25.103] rpc response                             method=datastreaming_start logId=4  err="too much time has elapsed since request was signed" result={} attempt=0 args="[\"0x69944a84\", \"0x37\", \"0xd9\", \"0x2e4a\", \"0xa\", \"0x7790f4c18955f9e473f7a98997e530df179048d9a11b373d1279a03aeeae54dc53d29baeb7115a0a599847a4ed8ef5fc227350ee5bfb07757ce77f74920fb64700\"]" errorData=null
    protocol_test.go:230: goroutine 250 [running]:
        runtime/debug.Stack()
        	/opt/hostedtoolcache/go/1.25.6/x64/src/runtime/debug/stack.go:26 +0x5e
        github.com/offchainlabs/nitro/util/testhelpers.RequireImpl({0x161f990, 0xc0000f5a40}, {0x16061e0, 0xc0008844e0}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/util/testhelpers/testhelpers.go:29 +0x9f
        github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic.func1()
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:230 +0x19b
        created by github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic in goroutine 221
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:223 +0x85
        
    protocol_test.go:230: �[31;1m [] too much time has elapsed since request was signed �[0;0m
--- FAIL: TestDataStreaming_PositiveScenario/Many_senders,_long_messages (0.11s)
TestDataStreaming_PositiveScenario
Stack Traces | 0.140s run time
=== RUN   TestDataStreaming_PositiveScenario
--- FAIL: TestDataStreaming_PositiveScenario (0.14s)
TestRedisProduceComplex/one_producer,_all_consumers_are_active
Stack Traces | 1.240s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
�[36mDEBUG�[0m[02-17|11:01:28.963] trimming                                 �[36mxTrimMinID�[0m=1771326087832-2  �[36mtrimmed�[0m=0 �[36mtrim-err�[0m=&lt;nil&gt;
�[36mDEBUG�[0m[02-17|11:01:28.963] Redis stream consuming                   �[36mconsumer_id�[0m=e0a4b868-40d8-4cf6-9052-1832199a728b �[36mmessage_id�[0m=1771326087834-3
�[36mDEBUG�[0m[02-17|11:01:28.963] consumer: setting result                 �[36mcid�[0m=e0a4b868-40d8-4cf6-9052-1832199a728b �[36mmsgIdInStream�[0m=1771326087834-3  �[36mresultKeyInRedis�[0m=result-key:stream:40894c63-0922-413e-8e51-188a033f215b.1771326087834-3
�[36mDEBUG�[0m[02-17|11:01:28.964] Redis stream consuming                   �[36mconsumer_id�[0m=bf0946bb-0926-4635-980c-4db780f9527e �[36mmessage_id�[0m=1771326087834-2
�[36mDEBUG�[0m[02-17|11:01:28.964] consumer: setting result                 �[36mcid�[0m=bf0946bb-0926-4635-980c-4db780f9527e �[36mmsgIdInStream�[0m=1771326087834-2  �[36mresultKeyInRedis�[0m=result-key:stream:40894c63-0922-413e-8e51-188a033f215b.1771326087834-2
�[36mDEBUG�[0m[02-17|11:01:28.964] consumer: xack                           �[36mcid�[0m=e0a4b868-40d8-4cf6-9052-1832199a728b �[36mmessageId�[0m=1771326087834-3
�[36mDEBUG�[0m[02-17|11:01:28.964] consumer: xack                           �[36mcid�[0m=bf0946bb-0926-4635-980c-4db780f9527e �[36mmessageId�[0m=1771326087834-2
�[36mDEBUG�[0m[02-17|11:01:28.964] Redis stream consuming                   �[36mconsumer_id�[0m=f8b0e4b1-7cbb-4075-8d94-1768afff17f3 �[36mmessage_id�[0m=1771326087834-1
�[36mDEBUG�[0m[02-17|11:01:28.964] consumer: xdel                           �[36mcid�[0m=bf0946bb-0926-4635-980c-4db780f9527e �[36mmessageId�[0m=1771326087834-2
�[36mDEBUG�[0m[02-17|11:01:28.964] consumer: setting result                 �[36mcid�[0m=f8b0e4b1-7cbb-4075-8d94-1768afff17f3 �[36mmsgIdInStream�[0m=1771326087834-1  �[36mresultKeyInRedis�[0m=result-key:stream:40894c63-0922-413e-8e51-188a033f215b.1771326087834-1
�[36mDEBUG�[0m[02-17|11:01:28.969] consumer: xdel                           �[36mcid�[0m=e0a4b868-40d8-4cf6-9052-1832199a728b �[36mmessageId�[0m=1771326087834-3
�[36mDEBUG�[0m[02-17|11:01:28.970] consumer: xack                           �[36mcid�[0m=3d6fe4b1-bace-4121-9234-e8b6c3da8b88 �[36mmessageId�[0m=1771326087833-6
�[36mDEBUG�[0m[02-17|11:01:28.970] consumer: xack                           �[36mcid�[0m=f8b0e4b1-7cbb-4075-8d94-1768afff17f3 �[36mmessageId�[0m=1771326087834-1
�[36mDEBUG�[0m[02-17|11:01:28.970] consumer: xdel                           �[36mcid�[0m=3d6fe4b1-bace-4121-9234-e8b6c3da8b88 �[36mmessageId�[0m=1771326087833-6
�[36mDEBUG�[0m[02-17|11:01:28.970] consumer: xdel                           �[36mcid�[0m=f8b0e4b1-7cbb-4075-8d94-1768afff17f3 �[36mmessageId�[0m=1771326087834-1
�[36mDEBUG�[0m[02-17|11:01:28.978] checkResponses                           �[36mresponded�[0m=69 �[36merrored�[0m=0 �[36mchecked�[0m=100
�[36mDEBUG�[0m[02-17|11:01:28.983] redis producer: check responses starting
�[36mDEBUG�[0m[02-17|11:01:29.001] checkResponses                           �[36mresponded�[0m=31 �[36merrored�[0m=0 �[36mchecked�[0m=31
�[36mDEBUG�[0m[02-17|11:01:29.044] Error destroying a stream group          �[36merror�[0m="dial tcp 127.0.0.1:36875: connect: connection refused"
--- FAIL: TestRedisProduceComplex/one_producer,_all_consumers_are_active (1.24s)

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@pmikolajczyk41 pmikolajczyk41 marked this pull request as ready for review February 16, 2026 14:18
@pmikolajczyk41
Copy link
Copy Markdown
Member Author

after merging #4391 and rebasing, CI will pass

Copy link
Copy Markdown
Contributor

@bragaigor bragaigor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bragaigor bragaigor assigned eljobe and unassigned bragaigor Feb 17, 2026
@eljobe eljobe enabled auto-merge February 17, 2026 16:42
@eljobe eljobe added this pull request to the merge queue Feb 17, 2026
Merged via the queue into master with commit 0fc8cbb Feb 17, 2026
27 checks passed
@eljobe eljobe deleted the pmikolajczyk/nit-4432-statics-2 branch February 17, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants