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

Feature: Disable balance accounting in the ledger #3192

Merged
merged 9 commits into from
Dec 13, 2021
Merged

Conversation

topocount
Copy link
Member

@topocount topocount commented Sep 21, 2021

Description

When utilizing an on chain grain integration, tracking account balances
in the SourceCred ledger makes little sense. These changes disable
balance accounting, while preserving the functionality key to
SourceCred, which is tracking distributions across identities. While
balances are no longer tracked, paid totals will continue to be. This
feature, combined with Distribution execution tracking, narrows the
scope of the ledgers focus to the state of distributions, and whether or
not they have been executed outside of SourceCred.

When account balance tracking is disabled, the following changes are
made to ledger behavior:

  • all grain balances are zeroed out in mutable accounts tracked by the
    ledger
  • grain transfers are disabled
  • The ledger stores the currently configured integrationCurrency at the instant
    accounting is disabled as externalCurrency. This allows for the configuration
    to be historically tracked in case the configuration is accidentally changed, and
    allows for more predictable behavior in the ledger in this mode. If the integrationCurrency
    needs to be updated, the disableAccounting method can just be re-run with the
    new currency to update the configuration within the ledger.
  • distributed grain is not added to a user's balance. the paid total is
    updated, however. Undistributed balances are tracked as a whole through
    the distribution tracking functionality added earlier.
  • identities without a relevant payout address will be deactivated
  • identities that have no relevant payout addresses configured cannot be
    activated. relevant means the external currency configured in the
    ledger's state.

Now that all integration functionality has settled in the ledger, the executeGrainIntegration
interface can be simplified and cleaned up. No information has been
lost; Config details can now simply be queried from the ledger directly.

Config inconsistencies are now tracked in the main/grain.js API file.
The main api will be tracking changes to the external currency config and
update the ledger dynamically before any integrations run. This seemed like
the best compromise between "magic" and usability. I think it's important that
the ledger tracks all integration currency changes for the purpose of transparency,
but also using a config file seems to be the best input method for now. This
tracking can be deprecated when we migrate to a webUI for config management.

test plan: unit tests have been updated

Test Plan

Unit tests included

Merge Plan

merge plan can be found here

Future Work

The current entry point is integration currency config in the grain.json config file. However, I'd really like to set up a CLI dialog for setting this and other integration config in the near-term. This is a hard requirement for the smart contract deployment for the merkle distribution integration, so I might as well include these few extra dialogs as a part of that story.

Update: I ended up just creating config entries in config/grain.json that are checked against the ledger every time grain distribution runs via the CLI.

@topocount topocount linked an issue Oct 25, 2021 that may be closed by this pull request
@topocount topocount force-pushed the accounting branch 3 times, most recently from 9d87eb4 to d6021e6 Compare November 1, 2021 18:13
Copy link
Member

@blueridger blueridger left a comment

Choose a reason for hiding this comment

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

I'm a little confused about what the entry point for this is going to be. Can you add some insight to the description? Like is there going to be a UI button that calls setExternalCurrency? What entry points will there be for disableAccounting?

I have some pretty structural comments in this review, so I will review unit tests once those are settle. First comment you should address: #3192 (comment)

packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/api/main/grain.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
@topocount
Copy link
Member Author

topocount commented Nov 2, 2021

I'm a little confused about what the entry point for this is going to be. Can you add some insight to the description? Like is there going to be a UI button that calls setExternalCurrency? What entry points will there be for disableAccounting?

@blueridger thanks for requesting this. Just added the following to the description:

The current entry point is integration currency config in the grain.json config file. However, I'd really like to set up a CLI dialog for setting this and other integration config in the near-term. This is a hard requirement for the smart contract deployment for the merkle distribution integration, so I might as well include these few extra dialogs as a part of that story.

Copy link
Member

@blueridger blueridger left a comment

Choose a reason for hiding this comment

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

For best clarity, I recommend that you add a consistent comment structure for all 4 of the new actions (both enable/set and disable/remove) of the form:

When <the other> is enabled: effect/behavior
When <the other> is disabled: effect/behavior

packages/sourcecred/src/api/main/grain.js Outdated Show resolved Hide resolved
packages/sourcecred/src/api/main/grain.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
When utilizing an on chain grain integration, tracking account balances
in the sourcecred ledger makes little sense. These changes disable
balance accounting, while preserving the functionality key to
SourceCred, which is tracking distributions across identities. While
balances are no longer tracked, paid totals will continue to be. This
feature, combined with Distribution execution tracking, narrows the
scope of the ledgers focus to the state of distributions, and whether or
not they have been executed outside of SourceCred.

When account balance tracking is disabled, the following changes are
made to ledger behavior:
- all grain balances are zeroed out in mutable accounts tracked by the
  ledger
- grain transfers are disabled
- distributed grain is not added to a user's balance. the paid total is
  updated, however. Undistributed balances are tracked as a whole through
  the distribution tracking functionality added earlier.
- identities without a relevant payout address will be deactivated
- identities that have no relevant payout addresses configured cannot be
  activated. relevant means the external currency configured in the
  ledger's state.

Test plan: Unit tests included
Now that all intergration funcitonality has settled in the ledger, this
interface can be simplified and cleaned up. No information has been
lost; Config details can now simply be queried from the ledger directly.

Config inconsistencies are now tracked in the main/grain.js API file.
The main api will be tracking changes to the external currency config and
update the ledger dynamically before any integrations run.

test plan: unit tests have been updated
Completely decoupled setting External Currencies from disabling
accounting. However, disabling accounting still requires an
external currency is set.

Cleaned up a bunch of cruft that I missed from the other changes
The new design centers the ledger as an audit log. All config changes
(except for the sink identity) should be recorded in the ledger before
any grain processing occurs. This setup is definitely inelegant, and I'm
looking forward to migrating away from it when we can manage configs via
some UI instead.

test plan: unit tests are updated for the config parser
- update docstrings to clearly communicate config effects
- naming functions
- ordering of functions
Ledger config was happening after the first grain distribution executed.
Now it runs as a hook before any grain distributions run.
Copy link
Member

@blueridger blueridger left a comment

Choose a reason for hiding this comment

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

It looks like you are using git please even though you are committing new changes as new commits. This makes it a little harder to track which commits are new. I'd recommend just using git push if you are not using git commit --amend

packages/sourcecred/src/cli/grain.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Show resolved Hide resolved
Comment on lines +947 to +949
if (!this._balanceAccountingEnabled) {
this._deactivateAccountsWithoutPayoutAddress();
}
Copy link
Member

Choose a reason for hiding this comment

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

This should go in the private method under the mutations line, right?

Copy link
Member Author

@topocount topocount Nov 26, 2021

Choose a reason for hiding this comment

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

it can't. Calls to public methods from private "processAction" methods that both ultimtely append to the ledger result in out-of-order timestamps.

This is an acceptable location because it only calls public methods under the hood. I'd like to keep this as a private method even though it only invokes a public method though because I don't want it to be a documented part of the API right now.

Copy link
Member

Choose a reason for hiding this comment

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

Ah cool

packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
packages/sourcecred/src/core/ledger/ledger.js Outdated Show resolved Hide resolved
@topocount
Copy link
Member Author

It looks like you are using git please even though you are committing new changes as new commits. This makes it a little harder to track which commits are new. I'd recommend just using git push if you are not using git commit --amend

@blueridger this PR has been open for a while, and I rebased to keep the changes up to date with the most recent updates in main. I've been appending changes via new commits, since rebasing doesn't change the date of a commit, it should be possbile to page into the relevant changes by referencing dates. I'll post deep links containing the relevant commits going forward.

@blueridger
Copy link
Member

Ahhh I see. No need to deep link, I can look for the timestamps. Thanks.

A grain integration might want to store some details within an instance,
such as a smart contract address. This update allows arbitrary updates
to a scoped object within the grain config file.

Test Plan:

Unit tests are provided at the grain integration interface. Integration
testing will be demonstrated in the test instance using the merkle
integration.
@topocount topocount merged commit b5709e6 into main Dec 13, 2021
@topocount topocount deleted the accounting branch December 13, 2021 15:51
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.

Implement Ledger accountingEnabled setting
2 participants