iotaledger / iri

IOTA Reference Implementation
Other
1.15k stars 370 forks source link

Walk Validator shouldn't hold state #786

Open GalRogozinski opened 6 years ago

GalRogozinski commented 6 years ago

Description

In the current implementation WalkValidator holds the ledger diff map (the addresses that have their state changed) and a set of a approved transactions that came from a previous walk. This object shouldn't hold those fields.

See: https://github.com/iotaledger/iri/blob/dev/src/main/java/com/iota/iri/service/tipselection/impl/WalkValidatorImpl.java#L38-L39

Motivation

Maintainability of the code. This object should be part of the business logic layer. Since it is not stateful it will be thread-safe (as long as we won't pass the same diff maps on different threads). It will also make it easier to inject it in the correct layers to objects that it will depend on.

Requirements

  1. The diff map and approvedHashes shouldn't be fields of any business logic object.
  2. WalkerValidator should be injected from IOTA.class to TipSelector

Am I planning to do it myself with a PR?

Until I am not the assignee, anyone can assign this issue to himself/herself.

paulhandy commented 6 years ago

The diff map, coupled with approvedHashes should be a part of tip selection - if it is desired for the new selected tip to be consistent with the selected tip of the previous run - in the case of multiple tip selection, and in the case where a model tip is first selected.

GalRogozinski commented 6 years ago

It will be. It is a design issue. I want WalkValidator to become an "application service", thus void of state.

GalRogozinski commented 5 years ago

Another problem of WalkValidator not a being dependency of TipSelector is that it can't be easily mocked for unit tests.