Commit Graph

143 Commits

Author SHA1 Message Date
Eric Mastro 24ad3fdea9
[statemachine] add additional tests
- test for multiple source states
- test for not allowing transition to self
2023-02-22 14:46:10 +11:00
Eric Mastro c80e3e5e2c
[statemachine] fix allowance of multiple source states 2023-02-21 17:21:23 +11:00
Eric Mastro b220f4198a
[statemachine] allow multiple source states in Transition
- multiple source states allowed in transition removed need for boilerplate subscription handling

TODO:
1. fix compilation for multiple transition source states
2. add tests for:
  - no transitioning to self
  - multiple source states in transition
3. Check how CancelledError gets caught in future callback
4. Remove Future[?State] from run return type?
2023-02-21 17:21:23 +11:00
Eric Mastro 8defc00bb0
[statemachine] WIP switch to declarative machine
- restoring and not restoring state both use the same setup for SalesAgent, by setting the SalesAgent’s state during instantiation, allowing it to react according to its state
- remove returning of next State from run (actual types yet to be changed)
- subscribe to onchain events, and use TransitionProperties to react (TODO: do not react from AnyState, but set to only states that make sense)
- create setError method in asyncstatemachine that handles setting of error properties
2023-02-21 17:21:23 +11:00
Eric Mastro 1a89c11d2c
[statemachine] properly prevent transition when clearing error 2023-02-21 17:21:23 +11:00
Eric Mastro 87db051ab2
[statemachine] add AnyState, support transition trigger from any state 2023-02-21 17:21:22 +11:00
Eric Mastro ea80387137
[statemachine] capture triggerable exceptions 2023-02-21 17:21:22 +11:00
Eric Mastro e651056701
[statemachine] cleanup 2023-02-21 17:21:22 +11:00
Eric Mastro ad9f5a4d51
[statemachine] check declared transitions after state change
- check declared transitions after state change
- make `Event` and `transition` public to enable external usage
- add exported machine.state proc
- add tests for machine.state
- add test TODO for not being able to check exception in run
- add test for checking declarative transitions after state transition
- remove onMoveToNextStateEvent as it was too confusing. Easier to read `Event.transition(state2, state3)`
2023-02-21 17:21:22 +11:00
Eric Mastro 0eacbea850
[statemachine] add additional tests for declarations 2023-02-21 17:21:22 +11:00
Eric Mastro 127adc0b8a
[statemachine] initial steps for declarative transitions
# Conflicts:
#	codex/utils/asyncstatemachine.nim
2023-02-21 17:21:22 +11:00
Mark Spanbroek 2035568b88
WIP switch to new statemachine model
Heavy work in progress, doesn't even compile yet,
this commit will be replaced by new cleaned up small commits

- callbacks are sync again
- agent.start(slots) is replaced by new state SaleStart
- disables explicit state transition tests for now; need to be replaced
2023-02-21 17:21:21 +11:00
Mark Spanbroek 59395d9bbd
[statemachine] adds a statemachine for async workflows
Allows events to be scheduled synchronously.

See https://github.com/status-im/nim-codex/pull/344

Co-Authored-By: Ben Bierens <thatbenbierens@gmail.com>
Co-Authored-By: Eric Mastro <eric.mastro@gmail.com>
2023-02-21 17:21:21 +11:00
Eric Mastro 47da5c1625
[marketplace] sales state machine: use slotState
Use `slotState` instead of `requestState` for sales state machine.

[marketplace] clean up
2023-02-21 17:21:21 +11:00
Eric Mastro 03a87636e7
[marketplace] support slotIndex no longer optional
Previously, SalesAgent.slotIndex had been moved to not optional. However, there were still many places where optionality was assumed. This commit removes those assumuptions.
2023-02-14 13:47:53 +01:00
Eric Mastro cb6e0bab6f
[marketplace] use async subscription event handlers 2023-02-14 13:47:53 +01:00
Mark Spanbroek b017359d13
[sales] make slotIndex non-optional 2023-02-14 13:47:52 +01:00
Mark Spanbroek 8a8e7aed70
[sales] fix: do not crash when fetching state fails 2023-02-14 13:47:52 +01:00
Mark Spanbroek 083e341592
[sales] cleanup 2023-02-14 13:47:52 +01:00
Mark Spanbroek 5f98f70714
[config] remove unused imports 2023-02-14 13:47:52 +01:00
Eric Mastro c0c604ce79
[marketplace] add missing file 2023-02-14 13:47:52 +01:00
Eric Mastro 437036a9a6
[marketplace] align with contract changes
- getState / state > requestState
- getSlot > getRequestFromSlotId
- support MarketplaceConfig
- support slotState, remove unneeded Slot type
- collateral > config.collateral.initialAmount
- remove proofPeriod contract call
- Revert reason “Slot empty” > “Slot is free”
- getProofEnd > read SlotState

Tests for changes
2023-02-14 13:47:52 +01:00
Eric Mastro 66b5ee52f9
[marketplace] clean up 2023-02-14 13:47:52 +01:00
Eric Mastro 1fbdb5d035
[marketplace] update to work with latest contracts 2023-02-14 13:47:51 +01:00
Eric Mastro 6aa2d35015
[marketplace] infer slot index from slotid
prevents reassigning a random slot index when restoring state from chain
2023-02-14 13:47:51 +01:00
Eric Mastro 19fe1b85e3
[marketplace] use requestId for mySlots 2023-02-14 13:47:51 +01:00
Eric Mastro 3db7b49537
[marketplace] handle slot filled by other host
Handle the case when in the downloading, proving, or filling states, that another host fills the slot.
2023-02-14 13:47:51 +01:00
Eric Mastro 0957c9adfa
PR comments
- add slotIndex to `SalesAgent` constructor
- remove `SalesAgent.init`
- rename `SalesAgent.init` to `start` and `SalesAgent.deinit` to `stop`.
- rename `SalesAgent. populateRequest` to `SalesAgent.retreiveRequest`.
- move availability removal to the downloading state. once availability is persisted to disk, it should survive node restarts.
-
2023-02-14 13:47:51 +01:00
Eric Mastro e8f87e3f52
[marketplace] fix ci issue with chronicles output 2023-02-14 13:47:51 +01:00
Eric Mastro 579da07ca6
[marketplace] sales state machine tests 2023-02-14 13:47:51 +01:00
Eric Mastro 67914249b6
[marketplace] move sale process to async state machine 2023-02-14 13:47:50 +01:00
Eric Mastro 54173f1f1c
[marketplace] add async state machine
Allows for `enterAsync` to be cancelled.
2023-02-14 13:47:50 +01:00
Eric Mastro fc95654ba8
[marketplace] make availability optional for node restart
# Conflicts:
#	tests/codex/testsales.nim
2023-02-14 13:47:50 +01:00
Eric Mastro fd398fc304
[marketplace] make on chain event callbacks async
# Conflicts:
#	tests/codex/helpers/mockmarket.nim
2023-02-14 13:47:50 +01:00
Eric Mastro 10815ac0b5
[marketplace] get active slots from chain
# Conflicts:
#	codex/contracts/market.nim
2023-02-14 13:47:50 +01:00
Eric Mastro df729be261
[marketplace] support latest contracts changes (#327)
* [marketplace] support removal of Storage contract

* [marketplace] change submod dep dagger-contracts to codex-contracts-eth
2023-01-19 16:58:04 +11:00
Dmitriy Ryajov 0beeefd760
Repo limits (#319)
* initial implementation of repo store

* allow isManifest on multicodec

* rework with new blockstore

* add raw codec

* rework listBlocks

* remove fsstore

* reworking with repostore

* bump datastore

* fix listBlocks iterator

* adding store's common tests

* run common store tests

* remove fsstore backend tests

* bump datastore

* add `listBlocks` tests

* listBlocks filter based on block type

* disabling tests in need of rewriting

* allow passing block type

* move BlockNotFoundError definition

* fix tests

* increase default advertise loop sleep to 10 mins

* use `self`

* add cache quota functionality

* pass meta store and start repo

* add `CacheQuotaNamespace`

* pass meta store

* bump datastore to latest master

* don't use os `/` as key separator

* Added quota limits support

* tests for quota limits

* add block expiration key

* remove unnesesary space

* use idleAsync in listBlocks

* proper test name

* re-add contrlC try/except

* add storage quota and block ttl config options

* clarify comments

* change expires key format

* check for block presence before storing

* bump datastore

* use dht with fixed datastore `has`

* bump datastore to latest master

* bump dht to latest master
2022-12-02 18:00:55 -06:00
markspanbroek cdd175279c
Fix nimble requirements (#305)
* [build] Update nim-ethers to 0.2.4

* [build] set correct lrucache requirement in nimble file
2022-11-16 13:10:23 +01:00
Dmitriy Ryajov 88f1be388a
fix `help`, `info`, add description for `loglevel` (#316)
* fix `help`, `info`, add description for `loglevel`

* add abbreviations for discovery params
2022-11-15 13:16:02 -06:00
Dmitriy Ryajov 5abf80cc69
Block download (#304)
* track inflight requests

* preperly handle precense updates

* trace number of of scheduled blocks

* invoke `payForBlocks` at the correct time

* reduntant block info on want list updates

* don't update prices in task handler

* PeerID -> PeerId

* cleanup

* proper log topic

* better chronicles topic filtering

* more trace logging

* sort want blocks

* wip - fix tests

* wip - fix tests, presence changes

* fix small test issue

* return price

* payment related changes

* misc

* re-enable payment tests

* fix warn wording

* fix `u256` conversion

* minor misc changes

* don't idle for so long on `encode`

* logging

* move buff

* disable cache by default

* disable cache by default

* fix streamOneBlock

* log node stopping/exiting

* trace logging

* don't stringify cid

* use `self`

* quick cleanup

* rename enums

* rename enums

* turns out we don't needs this test

* fix wording
2022-11-15 09:46:21 -06:00
Dmitriy Ryajov 5f9507cfcd
Blocks leak and inflight for pending blocks (#315)
* attach `wait` to handle fut

* fix crash when can't find a CID and timeout hits

the exception was not raised, thus a Nil was returned that was
than wrapped in an option, leading to crash.


Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>

* add inFlight flag

* adding pending blocks tests

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
Co-authored-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2022-11-15 00:12:05 -06:00
Dmitriy Ryajov f235cc6621
don't spawn queue requests (#313)
* don't spawn queue requests

* adjust list blocks idle timer

* increase timeout on failing test...
2022-11-14 18:01:05 -06:00
Dmitriy Ryajov f36dc54eda
Log topic filtering (#312)
* comment

* split out coders and add log level endpoin

* adjust info url

* add log filtering test

* don't stringify cid

* add log level test
2022-11-14 17:42:57 -06:00
markspanbroek 4175689745
Load purchase state from chain (#283)
* [purchasing] Simplify test

* [utils] Move StorageRequest.example up one level

* [purchasing] Load purchases from market

* [purchasing] load purchase states

* Implement myRequest() and getState() methods for OnChainMarket

* [proofs] Fix intermittently failing tests

Ensures that examples of proofs in tests are never of length 0;
these are considered invalid proofs by the smart contract logic.

* [contracts] Fix failing test

With the new solidity contracts update, a contract can only
be paid out after it started.

* [market] Add method to get request end time

* [purchasing] wait until purchase is finished

Purchase.wait() would previously wait until purchase
was started, now we wait until it is finished.

* [purchasing] Handle 'finished' and 'failed' states

* [marketplace] move to failed state once request fails

- Add support for subscribing to request failure events.
- Add supporting contract tests for subscribing to request failure events.
- Allow the PurchaseStarted state to move to PurchaseFailure once a request failure event is emitted
- Add supporting tests for moving from PurchaseStarted to PurchaseFailure
- Add state transition tests for PurchaseUnknown.

* [marketplace] Fix test with longer sleepAsync

* [integration] Add function to restart a codex node

* [purchasing] Set client address before requesting storage

To prevent the purchase id (which equals the request id)
from changing once it's been submitted.

* [contracts] Fix: OnChainMarket.getState()

Had the wrong method signature before

* [purchasing] Load purchases on node start

* [purchasing] Rename state 'PurchaseError' to 'PurchaseErrored'

Allows for an exception type called 'PurchaseError'

* [purchasing] Load purchases in background

No longer calls market.getRequest() for every purchase
on node start.

* [contracts] Add `$` for RequestId, SlotId and Nonce

To aid with debugging

* [purchasing] Add Purchasing.stop()

To ensure that all contract interactions have both a
start() and a stop() for

* [tests] Remove sleepAsync where possible

Use `eventually` loop instead, to make sure that we're
not waiting unnecessarily.

* [integration] Fix: handle non-json response in test

* [purchasing] Add purchase state to json

* [integration] Ensure that purchase is submitted before restart

Fixes test failure on slower CI

* [purchasing] re-implement `description` as method

Allows description to be set in the same module where the
state type is defined.

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>

* [contracts] fix typo

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>

* [market] Use more generic error type

Should we decide to change the provider type later

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
2022-11-08 08:10:17 +01:00
markspanbroek be32b9619b
Fixes loading of private key on Windows (#299)
Unix permissions don't work on Windows; 
adds check for correct ACL settings in Windows.
2022-11-07 15:54:24 +01:00
Michael Bradley c893b1f0cb
track latest nim-libp2p's master branch (#248)
* [build] track nim-libp2p's unstable branch

* cid formatIt change

* track nim-libp2p-unstable

* don't stringify cid

* Fixed testblockexc.nim

1. Assign price to blocks
2. Delete on node1 cached blocks from node2 before buying them again

* add trace logging

* init pricing info

* remove duplicate price setting

* cid serialization in trace logs

* bumping dht to latest main

* bump

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
Co-authored-by: Bulat-Ziganshin <bulat.ziganshin@gmail.com>
2022-11-02 11:40:28 -06:00
Dmitriy Ryajov 0ecbfcec9f
setup and persist private key (#292)
* setup and persist private key

* return dht record spr

* helper to remap multiaddr ip and port

* set/update discovery and announce addrs

* add nat and discovery IPs

* allow for announce and DHT addresses separatelly

* update tests

* check for nat or discoveryIp

* fix integration tests

* misc align

* don't share data dirs and and set bootstrap node

* add log scope

* remap announceAddrs after node start

* simplify discovery initialization

* make nat and disc-ip required

* add log scope don't init dht spr in constructor

* bump dht

* dissallow `0.0.0.0` for `--nat`
2022-11-01 18:58:41 -06:00
Dmitriy Ryajov ae46f4dc2f
add support for logging topics (#293)
* add support for logging topics

* add top level codex topic
2022-11-01 14:05:40 -06:00
Dmitriy Ryajov 6e4a8b86ab
Rework discovery (#288)
* use multiaddrs instead of ip/port

* rework to support updating spr

* fix tests

* fix compilation

* use base for base methods
2022-10-27 07:44:56 -06:00
Dmitriy Ryajov e50ea88411
Remove protobuf serialization (#289)
* add format for cid

* cid formatIt change

* track nim-libp2p-unstable

* rework probuf serialization for por

* add missing include

* removing nim protobuf serialization

* rollback to dht to main

* remove protobuf serialization import
2022-10-27 07:41:34 -06:00