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: add basic persistence, fixes #19

Merged
merged 22 commits into from
Mar 9, 2019
Merged

Conversation

kincaidoneil
Copy link
Contributor

@kincaidoneil kincaidoneil commented Mar 5, 2019

- prettier should also format js files
- tslint shouldn't auto-fix
- pro: error messages/stack traces are much clearer
- con: code coverage wasn't working right, but hopefully this fixes it
- fix linting errors/add readonly properties
- remove "settlement module" interface
- add wip commented out encryption code
- middlewares no longer implements full plugin interface since it's not necesary for now
- more concise helpers
- acknowledge failing tests (temporarily)
- delete config after each test
- no logs in ci triggers timeout errors when multiple funding txs are required
- temporarily addresses #15, at least for the Kava connector's config
- after deposit, refresh outgoing channel amount slightly later to ensure the channel exists
- remove unused function
- export util from lnd
- on Linux, positional writes aren't supported in append mode
- r+ mode doesn't overwrite file content by default
@codecov-io
Copy link

codecov-io commented Mar 5, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@01707d4). Click here to learn what that means.
The diff coverage is 93.68%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #19   +/-   ##
=========================================
  Coverage          ?   89.72%           
=========================================
  Files             ?       16           
  Lines             ?      662           
  Branches          ?       35           
=========================================
  Hits              ?      594           
  Misses            ?       59           
  Partials          ?        9
Impacted Files Coverage Δ
src/services/switch.ts 80% <ø> (ø)
src/services/stream-server.ts 83.33% <ø> (ø)
src/utils/store.ts 70% <ø> (ø)
src/engine.ts 100% <100%> (ø)
src/credential.ts 95.12% <100%> (ø)
src/settlement/machinomy.ts 91.93% <100%> (ø)
src/settlement/lnd.ts 96.07% <100%> (ø)
src/uplink.ts 90.47% <100%> (ø)
src/utils/crypto.ts 100% <100%> (ø)
src/utils/middlewares.ts 85% <100%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01707d4...537691d. Read the comment docs.

src/config.ts Outdated
credentials: state.credentials.map(credentialToConfig)
})

export const persistConfig = async (fd: number, state: State) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unlcear to me what fd is and what values it will take on depending on what happens. Maybe comment to clarify or change the name.

},
credentials: [],
uplinks: []
}

// TODO Add functionality to connect existing uplinks based on config
// (unnecessary/backburner until persistence is added)
// TODO Handle error cases if the uplinks fail to connect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, what happens currently if an uplink being restored fails to connect (say if the connector is offline)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hangs indefinitely...

}

/**
* Ensure that the given string is begins with given prefix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: string is begins -> string begins

Copy link
Member

@rhuairahrighairidh rhuairahrighairidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me, nice test refactor.

I think before adding encryption it might be worth looking at storing stuff in some key-value store (LevelDB maybe?). I think the change is really minor and it could fix a few problems while making the code nicer: 'instant' instead of timed persistence, encryption done for us, compatibility between windows/mac/linux file systems, ability to switch to an in memory store if needed.

t.context = await connect(process.env.LEDGER_ENV! as LedgerEnv)
})

test('after connect', async t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for removing this test?

* Ensure that the given string is begins with given prefix
* - Prefix the string if it doesn't already
*/
const prefixWith = (prefix: string, str: string) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to ensurePrefixedWith?

src/index.ts Outdated
}

export const connect = async (ledgerEnv: LedgerEnv = LedgerEnv.Testnet) => {
let state: State = {
const [fd, config] = await loadConfig()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't hard code the directory where data is stored.
Maybe add a dataDir: string arg to connect and loadConfig. Then set a default in connect to home/.switch/.

@kincaidoneil
Copy link
Contributor Author

@rhuairahrighairidh I opened #23 and #24 to track the persistence improvements

@kincaidoneil kincaidoneil merged commit b82befb into master Mar 9, 2019
@kincaidoneil kincaidoneil deleted the ko-persist-config branch March 14, 2019 14:44
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.

4 participants