nim-codex/vendor
Eric Mastro 25f68c1e4c
[marketplace] Load sales state from chain (#306)
* [marketplace] get active slots from chain

# Conflicts:
#	codex/contracts/market.nim

* [marketplace] make on chain event callbacks async

# Conflicts:
#	tests/codex/helpers/mockmarket.nim

* [marketplace] make availability optional for node restart

# Conflicts:
#	tests/codex/testsales.nim

* [marketplace] add async state machine

Allows for `enterAsync` to be cancelled.

* [marketplace] move sale process to async state machine

* [marketplace] sales state machine tests

* bump dagger-contracts

* [marketplace] fix ci issue with chronicles output

* 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.
-

* [marketplace] handle slot filled by other host

Handle the case when in the downloading, proving, or filling states, that another host fills the slot.

* [marketplace] use requestId for mySlots

* [marketplace] infer slot index from slotid

prevents reassigning a random slot index when restoring state from chain

* [marketplace] update to work with latest contracts

* [marketplace] clean up

* [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

* [marketplace] add missing file

* [marketplace] bump codex-contracts-eth

* [config] remove unused imports

* [sales] cleanup

* [sales] fix: do not crash when fetching state fails

* [sales] make slotIndex non-optional

* Rebase and update NBS commit

Rebase on top of main and update NBS commit to the CI fix.

* [marketplace] use async subscription event handlers

* [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.

* [marketplace] sales state machine: use slotState

Use `slotState` instead of `requestState` for sales state machine.

* [marketplace] clean up

* [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>

* [market] make market callbacks synchronous

* [statemachine] export Event

* [statemachine] ensure that no errors are raised

* [statemachine] add machine parameter to run method

* [statemachine] initialize queue on start

* [statemachine] check futures before cancelling them

* [sales] use new async state machine

- states use new run() method and event mechanism
- StartState starts subscriptions and loads request

* [statemachine] fix unsusbscribe before subscribe

* [sales] replace old state transition tests

* [sales] separate state machine from sales data

* [sales] remove reference from SalesData to Sales

* [sales] separate sales context from sales

* [sales] move decoupled types into their own modules

* [sales] move retrieveRequest to SalesData

* [sales] move subscription logic into SalesAgent

* [sales] unsubscribe when finished or errored

* [build] revert back to released version of nim-ethers

* [sales] remove SaleStart state

* [sales] add missing base method

* [sales] move asyncSpawn helper to utils

* [sales] fix imports

* [sales] remove unused variables

* [sales statemachine] add async state machine error handling (#349)

* [statemachine] add error handling to asyncstatemachine

- add error handling to catch errors during state.run
- Sales: add ErrorState to identify which state to transition to during an error. This had to be added to SalesAgent constructor due to circular dependency issues, otherwise it would have been added directly to SalesAgent.
- Sales: when an error during run is encountered, the SaleErrorState is constructed with the error, and by default (base impl) will return the error state, so the machine can transition to it. This can be overridden by individual states if needed.

* [sales] rename onSaleFailed to onSaleErrored

Because there is already a state named SaleFailed which is meant to react to an onchain RequestFailed event and also because this callback is called from SaleErrored, renaming to onSaleErrored prevents ambiguity and confusion as to what has happened at the callback callsite.

* [statemachine] forward error to state directly

without going through a machine method first

* [statemachine] remove unnecessary error handling

AsyncQueueFullError is already handled in schedule()

* [statemachine] test that cancellation ignores onError

* [sales] simplify error handling in states

Rely on the state machine error handling instead
of catching errors in the state run method

---------

Co-authored-by: Mark Spanbroek <mark@spanbroek.net>

* [statemachine] prevent memory leaks

prevent memory leaks and nil access defects by:
- allowing multiple subscribe/unsubscribes of salesagent
- disallowing individual salesagent subscription calls to be made externally (requires the .subscribed check)
- allowing mutiple start/stops of asyncstatemachine
- disregard asyncstatemachine schedules if machine not yet started

* [salesagent] add salesagent-specific tests

1. test multiple subscribe/unsubscribes
2. test scheduling machine without being started
3. test subscriptions are working correctly with external events
4. test errors can be overridden at the state level for ErrorHandlingStates.

---------

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
Co-authored-by: Ben Bierens <thatbenbierens@gmail.com>
2023-03-08 14:34:26 +01:00
..
asynctest@a236a5f0f3 Persist Dht providers (#257) 2022-09-29 20:16:59 -06:00
codex-contracts-eth@cde5436262 [marketplace] Load sales state from chain (#306) 2023-03-08 14:34:26 +01:00
combparser@ba4464c005 adding submodules 2021-11-25 09:37:12 +01:00
dnsclient.nim@fbb76f8af8 Add DHT (#75) 2022-04-13 10:32:35 -06:00
lrucache.nim@8767ade0b7 Add DHT (#75) 2022-04-13 10:32:35 -06:00
nim-bearssl@f4c4233de4 bump bearssl to latest 2022-09-27 12:56:07 +10:00
nim-blscurve@0237e4e0e9 Cleanup-manifest (#52) 2022-03-14 10:06:36 -06:00
nim-chronicles@7631f7b2ee track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-chronos@6525f4ce1d bumping chronos to latest master (#314) 2022-11-14 22:15:37 -06:00
nim-confutils@0435e67832 Minor cleanup and update deps (#42) 2022-01-12 16:19:37 -06:00
nim-contract-abi@61f8f59b39 Fix nimble requirements (#305) 2022-11-16 13:10:23 +01:00
nim-datastore@44c198b96a Repo limits (#319) 2022-12-02 18:00:55 -06:00
nim-eth@5885f638e4 Fix vendor/nim-eth (#246) 2022-09-12 21:30:16 -06:00
nim-ethers@e462649aec Fix nimble requirements (#305) 2022-11-16 13:10:23 +01:00
nim-faststreams@1b561a9e71 adding submodules 2021-11-25 09:37:12 +01:00
nim-http-utils@e88e231dfc track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-json-rpc@5a28176080 feat: integrate dagger contracts 2022-02-04 15:34:56 +11:00
nim-json-serialization@e5b18fb710 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-leopard@ae043fd262 [build] Update nim-leopard to version 0.1.0 (#310) 2022-11-15 09:05:52 +01:00
nim-libbacktrace@b29c22ba0e Bump libbacktrace and secp256k1 2022-06-28 11:04:18 +03:00
nim-libp2p@a3e9d1ed80 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-libp2p-dht@4375b92298 Repo limits (#319) 2022-12-02 18:00:55 -06:00
nim-metrics@743f81d4f6 adding submodules 2021-11-25 09:37:12 +01:00
nim-nat-traversal@27d314d65c Speed up development (#303) 2022-11-14 14:50:00 +01:00
nim-nitro@6b4c455bf4 Fix version conflict on nimble install 2022-05-19 09:36:47 +02:00
nim-presto@3984431dc0 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-secp256k1@5340cf1881 Bump libbacktrace and secp256k1 2022-06-28 11:04:18 +03:00
nim-serialization@493d18b829 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-sqlite3-abi@fda455cfea [build] add github.com/arnetheduck/nim-sqlite3-abi to vendor 2022-08-08 02:12:43 -05:00
nim-stew@0c379cf1d8 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-taskpools@8d408ac6cf Cleanup-manifest (#52) 2022-03-14 10:06:36 -06:00
nim-toml-serialization@4e15e00ed9 Node setup (#32) 2022-01-10 09:32:56 -06:00
nim-unittest2@02c49b8a99 Node setup (#32) 2022-01-10 09:32:56 -06:00
nim-websock@7b2ed397d6 track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
nim-zlib@74cdeb54b2 feat: integrate dagger contracts 2022-02-04 15:34:56 +11:00
nimbus-build-system@1cf6a1b18c Fix CI (#339) 2023-02-06 17:15:02 +01:00
nimcrypto@a5742a9a21 adding submodules 2021-11-25 09:37:12 +01:00
questionable@30e4184a99 [build] update questionable to 0.10.6 2022-09-29 10:16:41 +02:00
stint@036c71d06a adding submodules 2021-11-25 09:37:12 +01:00
upraises@ff4f8108e4 adding submodules 2021-11-25 09:37:12 +01:00