Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: the daemon should send the voided transactions when received from the fullnode #8

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
07b1b3e
feat: initial commit
andreabadesso Apr 1, 2021
f47eff9
feat: using generator to download blocks to be able to cancel it when…
andreabadesso Apr 2, 2021
e0d6fa4
chore: updated package.json, lock and tsconfig
andreabadesso Apr 2, 2021
7a7b6ab
chore: removed .env from git
andreabadesso Apr 2, 2021
f112121
feat: resetting blocks on syncing state entry and moving to idle when…
andreabadesso Apr 2, 2021
a1059d5
feat: checking if our best block is still valid (not voided) before c…
andreabadesso Apr 6, 2021
514e50f
refactor: handling errors better by yielding instead of throwing
andreabadesso Apr 6, 2021
501dcc3
refactor: using bi-directional callbacks on state machine instead of …
andreabadesso Apr 6, 2021
2d5831c
feat: using hathorLib Connection class to maintain a connection to th…
andreabadesso Apr 6, 2021
7a431d9
feat: starting the state machine only on START event
andreabadesso Apr 6, 2021
2473f7a
feat: added type to generator and yields
andreabadesso Apr 6, 2021
15b359f
feat: added tests for utils methods
andreabadesso Apr 8, 2021
95018d8
refactor: moved state machine methods to a dedicated file
andreabadesso Apr 8, 2021
8d8b42a
fix: typo when parsing outputs
andreabadesso Apr 8, 2021
92a5d50
feat: added tests for the state machine
andreabadesso Apr 8, 2021
a7e9039
chore: added baseUrl to prevent warnings
andreabadesso Apr 8, 2021
ace3568
feat: transition to reorg when a reorg is detected
andreabadesso Apr 8, 2021
c28cbcb
docs: added README
andreabadesso Apr 8, 2021
4c152de
feat: getting NETWORK from env var
andreabadesso Apr 8, 2021
942a174
fix: handling lambda call failures
andreabadesso Apr 12, 2021
1d2b1f5
chore: removed size.yml github action (came from tsdx template)
andreabadesso Apr 12, 2021
211417e
docs: added comment explaining the block sync strategy on ws events
andreabadesso Apr 13, 2021
e8daa1c
docs: added comment explaining state updates from ws conn
andreabadesso Apr 13, 2021
3d3cbed
chore: removed unused and commented import on machine and commented u…
andreabadesso Apr 13, 2021
749d968
docs: added comment on the machine refering to the README
andreabadesso Apr 13, 2021
5184025
refactor: getting constant from hathor-lib and removed useless commen…
andreabadesso Apr 13, 2021
cc6b152
feat: typed prepareTx
andreabadesso Apr 14, 2021
cf3a623
fix: returning success false if a failure has ocurred inside the tx loop
andreabadesso Apr 14, 2021
0b10072
fix: added missing attributes to PreparedTx type
andreabadesso Apr 14, 2021
f054877
docs: added docstring to util methods
andreabadesso Apr 14, 2021
a168187
feat: using a LRU cache for transactions
andreabadesso Apr 14, 2021
5d393bc
refactor: removed misleading log
andreabadesso Apr 14, 2021
9354570
feat: loading wallet_service_local_url from env variables
andreabadesso Apr 20, 2021
fd11312
docs: added a TODO to replace the getFullNodeBestBlock API
andreabadesso Apr 20, 2021
8bc8790
fix: added missing type to sendTx parameter
andreabadesso Apr 20, 2021
4e30d3f
fix: added missing types and fixed lint on LRU cache
andreabadesso Apr 20, 2021
742f777
Added dockerfile to the project (#4)
andreabadesso May 4, 2021
bff6a3f
docs: added a simple explaination on how to run locally, build and ru…
andreabadesso May 4, 2021
cb1a5b3
chore: updated state machine diagram URL to render automatically
andreabadesso May 4, 2021
6b27d88
docs: added missing hathor header
andreabadesso May 4, 2021
d130090
feat: added winston as a logger and refactored console.logs to use it
andreabadesso May 4, 2021
c5e1e4b
refactor: moved api methods to src/api
andreabadesso May 4, 2021
36578e0
fix: winston import breaking production build
andreabadesso May 5, 2021
c0ce52c
refactor: using wallet util method to get token index
andreabadesso May 5, 2021
e3ae097
refactor: changed reorg message
andreabadesso May 5, 2021
e210f76
refactor: improved blocks download message
andreabadesso May 5, 2021
f654dbe
refactor: using a better algorithm to filter unique txs
andreabadesso May 5, 2021
1b3435e
docs: added comment explaining Map queue order
andreabadesso May 5, 2021
fd840b2
fix: typo
andreabadesso May 6, 2021
908acaf
feat: typed yield result from generator
andreabadesso May 6, 2021
6d80493
feat: added type and docstring to onReceive from syncHandler
andreabadesso May 6, 2021
07b9c1e
refactor: using strict, refactor types to pass tslint
andreabadesso May 6, 2021
65f3774
fix: token creation tx was not sending token_name and token_symbol
andreabadesso May 6, 2021
09ce983
fix: breaking type on fullnode response
andreabadesso May 17, 2021
07c4624
feat: logging full data instead of data.Response on lambda response
andreabadesso May 17, 2021
1e78060
tests: removed isVoided from tx
andreabadesso May 17, 2021
83d2070
tests: fix typo on tests, clearing all mocks before every test instea…
andreabadesso May 17, 2021
9b01f07
tests: fix test by using the hathorLib to define whether a tx is a bl…
andreabadesso May 17, 2021
9eb23a9
feat: typed raw tx response from fullnode
andreabadesso May 17, 2021
9a37b7f
refactor: typed rawTx and refactored types
andreabadesso May 17, 2021
3ff7143
chore: set build output to cjs as the project is node-only
andreabadesso May 17, 2021
d8b3f67
chore: removed dom from lib
andreabadesso May 17, 2021
b4c2e15
feat: added spent_by and token to RawOutput and RawInput to handle bl…
andreabadesso May 17, 2021
135191c
chore: ignoring some ts errors that can be handled by typing for now.
andreabadesso May 17, 2021
3b7f2ea
chore: using strict: true
andreabadesso May 17, 2021
7bcdcf7
feat: ignoring genesis transactions before sending them to the wallet…
andreabadesso May 23, 2021
81c5f05
chore: empty commit
andreabadesso Jun 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push]
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['10.x', '12.x', '14.x']
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2

- name: Build
run: yarn build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.log
.DS_Store
node_modules
dist
.env
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2020 Hathor Labs
# This software is provided ‘as-is’, without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
# This software cannot be redistributed unless explicitly agreed in writing with the authors.

FROM node:14 AS builder

COPY package.json /app/

RUN cd /app && npm install --production

COPY . /app/

RUN cd /app && npm run build

FROM node:14-alpine3.13 AS builder

COPY --from=builder /app/dist/ /app/
COPY --from=builder /app/node_modules /app/node_modules

CMD node /app/index.js
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Hathor Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Hathor Wallet Service -- Sync Daemon

## Running

### Local environment

#### System dependencies

You need nodejs installed on your enviroment, we are using the latest Active LTS version (v14.16.1) on the dev environment. You can read more about installing nodejs on https://nodejs.org/en/download/package-manager/

#### Clone the project and install dependencies

`git clone https://github.com/HathorNetwork/hathor-wallet-service-sync_daemon.git && npm install`

#### Add env variables or an .env file to the repository:

Example:

```
STAGE=local
NETWORK=testnet
MAX_ADDRESS_GAP=20
SERVICE_NAME=hathor-wallet-service
DEFAULT_SERVER=http://fullnode_url/v1a/
```

`STAGE` - Wallet-Service's deployment stage, e.g. `local`, `production`, `staging`
`NETWORK` - The current hathor network we want to connect to
`MAX_ADDRESS_GAP` - The full-node configured GAP between addresses
`SERVICE_NAME` - The Wallet-Service's service name as it was registered on AWS
`DEFAULT_SERVER` - The full-node API url

If the wallet-service is not running locally, you also need to specify the AWS-SDK env variables:

```
AWS_REGION="us-east-1"
AWS_DEFAULT_REGION="us-east-1"
AWS_ACCESS_KEY_ID="..."
AWS_SECRET_ACCESS_KEY="..."
```

#### Run:

`npm start`


### Deploy

The recommended way to deploy this service is to use docker.

#### Building the image:

`docker build -t hathor/sync-daemon .`

#### Running:

```
docker run -d -e STAGE="production" \
-e NODE_ENV="production" \
-e AWS_REGION="us-east-1" \
-e AWS_DEFAULT_REGION="us-east-1" \
-e AWS_ACCESS_KEY_ID="..." \
-e AWS_SECRET_ACCESS_KEY="..." \
-e NETWORK="testnet" \
-e MAX_ADDRESS_GAP=20 \
-e NETWORK="testnet" \
-e SERVICE_NAME="hathor-wallet-service" \
-e DEFAULT_SERVER="http://fullnode:8082/v1a/" \
-ti localhost/hathor/sync-daemon
```

In this example, we are passing the env variables to the container and running as a daemon (`-d`). We are also expecting a fullnode to be running on fullnode:8082.

## State Machine

The state machine diagram can be visualized at https://xstate.js.org/viz/?gist=7299c0ed0ce189bc121a06dce1e11638

## States:

### Idle

The machine starts at the idle state, it will stay there until a `NEW_BLOCK` action is received.

Every time the state of the machine is transitioned to `idle`, the machine will check if `hasMoreBlocks` is set on the state context. If it is, the machine will transition to `syncing`.

#### Actions:
`NEW_BLOCK`: When a `NEW_BLOCK` action is received, the machine will transition to the `syncing` state.

### Syncing

Everytime the state of the machine is transitioned to `syncing`, the machine will invoke the `syncHandler` service that will start syncing new blocks.

#### Actions:
`NEW_BLOCK`: When a `NEW_BLOCK` action is received, the machine will assign `true` to the `hasMoreBlocks` context on the state, so the next time we transition to `IDLE`, the machine will know that there are more blocks to be downloaded.
`DONE`: When a `DONE` action is received, the machine will transition to `idle` to await for new blocks
`ERROR`: When a `ERROR` action is received, the machine will transition to the `failure` state
`REORG`: When a `REORG` action is received, the machine will transition to the `reorg` state
`STOP`: When a `STOP` action is received, the machine will transition to the `idle` state

### Failure

This is a `final` state, meaning that the machine will ignore all actions and wait for a manual restart.

This state can trigger actions to try to automatically solve issues or notify us about it.

### Reorg

This is temporarily a `final` state, this will be changed on a new PR with the reorg code.
Loading