Skip to content

fix: heartbeat timestamp unit, transfer normalization, validator propagation, error handling - #46

Open
Alicepoltora wants to merge 1 commit into
AdvaitaLabs:mainfrom
Alicepoltora:fix/heartbeat-timestamp-transfer-normalization-and-more
Open

fix: heartbeat timestamp unit, transfer normalization, validator propagation, error handling#46
Alicepoltora wants to merge 1 commit into
AdvaitaLabs:mainfrom
Alicepoltora:fix/heartbeat-timestamp-transfer-normalization-and-more

Conversation

@Alicepoltora

Copy link
Copy Markdown

Summary

Fixes 4 bugs across the RPC, validator, and network layers:

1. Heartbeat timestamp: seconds instead of milliseconds

setu-rpc/src/registration.rs:208

The heartbeat client used as_secs() to produce the timestamp, but every other timestamp in the codebase uses milliseconds (discovery timestamp_ms, state sync last_update_ms, config timeouts in _ms). Any staleness check was off by 1000×, causing false timeout or false alive decisions.

Fix: as_secs()as_millis() as u64

2. Transfer forwards unnormalized addresses — anti-replay bypass

setu-validator/src/user_handler.rs:1144

The anti-replay precheck and canonical signature used normalized_from/normalized_to (lowercase), but SubmitTransferRequest forwarded the original-case request.from/request.to. If the downstream TEE runtime derives the nonce marker object from the unnormalized address, it computes a different marker than the one pre-checked, rendering the anti-replay defense ineffective.

Fix: Forward normalized_from/normalized_to instead of request.from/request.to

3. add_validator not propagated to consensus engine

setu-validator/src/consensus_integration.rs:846

add_validator() updated the local ValidatorSet copy but did NOT call self.engine.add_consensus_validator(info). This meant new validators added via this path were invisible to quorum calculation and leader election. add_peer_validator() (line 475) already did this correctly.

Fix: Added self.engine.add_consensus_validator(info).await after the local update

4. GenericHandler swallows errors — returns 200 OK with empty body

crates/setu-network-anemo/src/generic_handler.rs:112

When a message handler returned Err(e), the service wrapper logged a warning and returned Ok(Response::new(Bytes::new())) — a 200 OK with empty body. Callers had no way to distinguish an error from a legitimate empty response.

Fix: Return the error message in the response body with a __HANDLER_ERROR__: prefix so callers can detect and parse errors.

Testing

  • cargo check -p setu-rpc -p setu-validator -p setu-network-anemo — passes
  • cargo test -p setu-rpc -p setu-network-anemo — all pass
  • cargo test -p consensus -p setu-types — 338/339 pass (1 pre-existing golden-file failure)

Files changed

  • setu-rpc/src/registration.rsas_secs()as_millis() as u64
  • setu-validator/src/user_handler.rs — forward normalized addresses
  • setu-validator/src/consensus_integration.rs — propagate to engine
  • crates/setu-network-anemo/src/generic_handler.rs — encode error in response

…agation, error handling

1. Fix heartbeat timestamp: seconds → milliseconds (setu-rpc/src/registration.rs)
   - Heartbeat used as_secs() while entire codebase uses milliseconds
   - Staleness checks were off by 1000×, causing false timeout/alive decisions

2. Fix transfer forwards unnormalized addresses (setu-validator/src/user_handler.rs)
   - Anti-replay precheck and signature used normalized (lowercase) addresses
   - But SubmitTransferRequest forwarded original-case addresses
   - Downstream TEE runtime computed different nonce marker → precheck bypass

3. Fix add_validator not propagated to consensus engine (setu-validator/src/consensus_integration.rs)
   - add_validator() updated local ValidatorSet but NOT the engine's copy
   - New validators were invisible to quorum/leader election
   - add_peer_validator() already did this correctly; add_validator() was missing it

4. Fix GenericHandler swallowing errors (crates/setu-network-anemo/src/generic_handler.rs)
   - Handler errors returned 200 OK with empty body
   - Callers could not distinguish errors from legitimate empty responses
   - Now returns error message in body with __HANDLER_ERROR__: prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant