-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
PlantUML diagrams #8712
Merged
mergify
merged 54 commits into
cosmos:master
from
hjorthjort:hjorthjort/sequence-diagrams
Apr 6, 2021
Merged
PlantUML diagrams #8712
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
31a1f74
Overview of keepers in object capability model (OCM)
2c4ba34
Updates to the spec, making clarifications
a4998f3
Create a sequence diagram of a (fresh) delegation
73c21a8
Misc notes, not yet decided where to put them
8bcf73a
Description of the shares abstraction in validators
hjorthjort b476faf
Model all keeper dependencies and move the UML file to docs
hjorthjort 151a4a9
Move and rename delegation sequence diagram
hjorthjort 11e1946
Move shares description
hjorthjort 89b5a8a
Remove TODO
hjorthjort d221b6f
Diagram touch-ups
hjorthjort d151fa1
Add how consensus power is calculated
hjorthjort d791e12
remove temp file
hjorthjort f6f8161
Diagram improvements
hjorthjort 92050cd
Describe slashing in more detail
hjorthjort f3d5e8f
Describe redelegation
hjorthjort e717f07
Describe unbonding
hjorthjort 6f9c7a7
Delegation updates
hjorthjort c878b23
Delegation updates
hjorthjort c42bf87
Make a diagram describing overall transaction flow
hjorthjort ed32e4d
Add delegation flows for the events of tokens being bonded/unbonding/…
hjorthjort 30c3933
Grammar fix
hjorthjort 02dbc23
Diagram updates: distinguish alts, remove numbering.
hjorthjort ca7e6d6
Use groups instead of "func:" participants
hjorthjort b731d3c
Merge pull request #22 from hjorthjort/hjorthjort/documentation
hjorthjort 61377cd
Merge remote-tracking branch 'upstream/master'
hjorthjort cbbeb3b
Remove unused keepers from dependency diagram
hjorthjort 9e4f11e
Add title to unbonding diagram
hjorthjort c00da7a
Move keeper dependencies
hjorthjort fb07c03
small doc updates
hjorthjort fd1382e
remove numbers on sequence diagram
hjorthjort 48f4d5a
!!!WIP EndBlock
hjorthjort 04f6b48
Explain "Last"-prefix in storage
hjorthjort 5762dad
Remove `panic` step (they are supposed to never happen)
hjorthjort ea6c9d5
EndBlock sequence diagram (with TODOs)
hjorthjort 25ca4c3
Add TODO
hjorthjort ed646c0
More visible TODOs
hjorthjort 6abbe9d
Remove numbering
hjorthjort 22fc57d
Complete EndBlock
hjorthjort 5ca1ae8
Remove numbering
hjorthjort 27720b0
Remove TODOs and update title
hjorthjort 7a1929b
add title back
hjorthjort cc6aedf
Merge branch 'master' into hjorthjort/sequence-diagrams
hjorthjort 6a0e944
remove endblock seq-diagram
hjorthjort 7b4ab55
Make power index update conditional on not being jailed
hjorthjort 4dda170
update title
hjorthjort b02943d
Move files to /docs
hjorthjort 8fb7a40
Install PlantUML and compile images to png and txt
hjorthjort 1a0d992
Use transaction flow in documentation
hjorthjort 656a278
Use staking UML in staking docs
hjorthjort 47e330d
Clarify uml with inline doc
hjorthjort 13a39d0
Merge branch 'master' into hjorthjort/sequence-diagrams
hjorthjort aa6950b
Add keeper deps diagram to docs
hjorthjort 6c5650c
Only produce SVG images
hjorthjort 44dd0eb
Merge branch 'master' into hjorthjort/sequence-diagrams
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
title: Redelegation | ||
|
||
msgServer -> keeper : BeginRedelegation(delAddr, valSrcAddr, valDstAddr, sharesAmount) | ||
participant "keeper (staking)" as keeper | ||
keeper -> keeper : get number of sharew | ||
note left: If the delegator has more shares than the total shares in the validator\n(due to rounding errors), then just withdraw the max number of shares. | ||
keeper -> keeper : check the redelegation uses correct denom | ||
|
||
alt valSrcAddr == valDstAddr | ||
keeper --> msgServer : error | ||
end | ||
alt transitive redelegation | ||
keeper --> msgServer : error | ||
end | ||
alt already has max redelegations | ||
keeper --> msgServer : error | ||
note left : this is the number of redelegations for a specific (del, valSrc, valDst) triple\ndefault : 7 | ||
end | ||
|
||
|
||
keeper -> keeper : Unbond(del, valSrc) returns returnAmount | ||
... | ||
note left : See unbonding diagram | ||
|
||
alt returnAmount is zero | ||
keeper -> msgServer : error | ||
end | ||
|
||
keeper -> keeper : Delegate(del, returnAmount, status := valSrc.status, valDst, subtractAccount := false) | ||
note left : See delegation diagram | ||
... | ||
|
||
alt validator is unbonded | ||
keeper -> msgServer : current time | ||
end | ||
|
||
alt unbonding not complete, or just started | ||
database store | ||
keeper -> store : create redelegation object | ||
keeper -> store : insert redelegation in queue, to be processed at the appropriate time | ||
end | ||
|
||
msgServer <-- keeper : completion time of the redelegation | ||
msgServer -> msgServer : emit event: delegator, valSrc, valSrc,\nsharesAmount, completionTime | ||
|
||
@enduml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
title: Delegating (currently undelegated funds delegator) | ||
|
||
participant "msgServer (staking)" | ||
participant "keeper (staking)" as keeper | ||
participant validator | ||
participant keeper.bankKeeper | ||
participant vestingAccount | ||
participant ctx.EventManager | ||
|
||
database store | ||
|
||
"msgServer (staking)" -> keeper : Delegate(Context, DelegatorAddress, Amount, Validator, tokenSrc := Unbonded) | ||
|
||
alt exchange rate is invalid (tokens in validator is 0) | ||
keeper --> "msgServer (staking)" : error | ||
end | ||
|
||
alt perform a new delegation | ||
keeper -> keeper : delegation := create delegation object | ||
keeper -> keeper : BeforeDelegationCreated hook | ||
note left: Calls IncrementValidatorPeriod (Used to calculate distribution) in keeper/validator.go | ||
else delegation exists, more tokens being added | ||
keeper -> keeper : BeforeDelegationModified hook | ||
note left: withdraw current delegation rewards (and increment period) | ||
end | ||
|
||
alt delegating from an account (subtractTokens == true) | ||
keeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule | ||
group DelegateCoinsFromAccountToModule function | ||
keeper.bankKeeper -> keeper.bankKeeper : DelegateCoinsFromAccountToModule | ||
keeper.bankKeeper -> keeper.bankKeeper : DelegateCoins | ||
group DelegateCoins function | ||
keeper.bankKeeper --> keeper.bankKeeper : Check the delegator has enough balances of all tokens delegated | ||
keeper.bankKeeper --> keeper.bankKeeper : Track delegation (register that it exists to keep track of it) | ||
alt validator is currently bonded | ||
keeper.bankKeeper --> store : Transfer tokens from delegator to BondedTokensPool. | ||
else validator is currently unbonded or unbonding | ||
keeper.bankKeeper --> store : Transfer tokens from delegator to NotBondedTokensPool. | ||
end | ||
group trackDelegation function | ||
keeper.bankKeeper -> keeper.bankKeeper : trackDelegation | ||
alt delegator is a vesting account | ||
keeper.bankKeeper -> vestingAccount : keep track of this delegation | ||
end | ||
end | ||
end | ||
end | ||
keeper <-- keeper.bankKeeper : nil (success) | ||
else moving tokens between pools (subtractTokens == false) | ||
alt delegator tokens are not bonded but validator is bonded | ||
keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(notBondedPool, bondedPool, coins) | ||
else delegator tokens are bonded but validator is not bonded | ||
keeper -> keeper.bankKeeper : SendCoinsFromModuleToModule(bondedPool, notBondedPool, coins) | ||
end | ||
group SendCoins function | ||
keeper.bankKeeper -> keeper.bankKeeper : SendCoins | ||
keeper.bankKeeper -> ctx.EventManager : Emit TransferEvent(to, from, amount) | ||
alt amount of spendable (balance - locked) coins too low | ||
keeper <-- keeper.bankKeeper : error | ||
end | ||
keeper.bankKeeper -> store : subtract balance from sender | ||
keeper.bankKeeper -> store : add balance to recipient | ||
end | ||
end | ||
|
||
keeper -> validator : AddTokensFromDel | ||
validator -> validator : calculate number of shares to issue | ||
note left: If there are no shares (validator being created) then 1 token = 1 share.\nIf there are already shares, then\nadded shares = (added tokens amount) * (current validator shares) / (current validator tokens) | ||
|
||
validator -> validator : add delegated tokens to validator | ||
keeper <-- validator : validator, addedShares | ||
keeper -> store : update validator state | ||
keeper -> keeper: calculate new validator's power | ||
note left : Number of tokens divided by PowerReduction (default: 1,000,000,000,000,000,000 = 10^18) | ||
alt validator is not jailed | ||
keeper -> store : update validator's power in power index | ||
note left : the power index has entries shaped as 35 || power || address.\nThis makes the validators sorted by power, high to low. | ||
end | ||
|
||
keeper -> keeper : AfterDelegationModified hook | ||
note left: Calls initializeDelegation\nStore the previous period\nCalculate the number of tokens from shares\n(shares the delegator has) * (tokens in delegation object)/(total tokens delegated to the validator)\nStore delegation starting info. | ||
"msgServer (staking)" <-- keeper : newShares (ignored by Delegate function) | ||
|
||
|
||
"msgServer (staking)" -> "msgServer (staking)" : Emit event: Delegation(ValidatorAddress) | ||
"msgServer (staking)" -> "msgServer (staking)" : Emit event: Message(DelegatorAddress) | ||
"msgServer (staking)" -> "msgServer (staking)" : telemetry(Amount, Denom) | ||
|
||
@enduml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@startuml | ||
'https://plantuml.com/class-diagram | ||
|
||
title: The dependencies between Keepers (Feb 2021) | ||
|
||
abstract class Staking | ||
abstract class Distribution | ||
abstract class Slashing | ||
abstract class Evidence | ||
abstract class Bank | ||
abstract class "Auth/Account" as Auth | ||
abstract class Gov | ||
abstract class Mint | ||
|
||
Staking <|-- Mint | ||
Bank <|-- Mint | ||
|
||
Staking <|-- Gov | ||
Bank <|-- Gov | ||
Auth <|-- Gov | ||
|
||
Auth <|-- Bank | ||
|
||
Bank <|-- Distribution | ||
Auth <|-- Distribution | ||
Staking <|-- Distribution | ||
|
||
Staking <|-- Evidence | ||
Slashing <|-- Evidence | ||
|
||
Staking <|-- Slashing | ||
|
||
Auth <|-- Staking | ||
Bank <|-- Staking | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
What happens after a transaction is unmarshalled and is processed by the SDK? | ||
|
||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
actor User | ||
User -> baseApp : Transaction Type<Tx> | ||
baseApp -> router : Route(ctx, msgRoute) | ||
router --> baseApp : handler | ||
baseApp -> handler: Msg<Tx>(Context, Msg(...)) | ||
handler -> msgServer : <Tx>(Context, Msg) | ||
alt addresses invalid, denominations wrong, etc. | ||
msgServer --> handler : error | ||
end | ||
msgServer -> keeper : perform action, update context | ||
keeper --> msgServer : results, error code | ||
msgServer -> Context.EventManager : Emit relevant events | ||
msgServer -> msgServer : maybe wrap results in more structure | ||
msgServer --> handler : result, error code | ||
baseApp <-- handler : results, error code | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@startuml | ||
'https://plantuml.com/sequence-diagram | ||
|
||
title: Undelegate | ||
|
||
msgServer -> keeper : Undelegate(delAddr, valAddr, tokenAmount) | ||
|
||
keeper -> keeper : calculate number of shares the tokenAmount represents | ||
|
||
alt wrong denom | ||
msgServer <-- keeper : error | ||
end | ||
|
||
group Unbond(delAddr, valAddr, shares) | ||
keeper -> keeper: BeforeDelegationSharesModified hook | ||
alt no such delegation | ||
keeper --> msgServer : error | ||
end | ||
alt not enough shares | ||
keeper --> msgServer : error | ||
end | ||
alt delegator is the operator of the validator\nand validator is not already jailed\nand unbonding would put self-delegation under min threshold | ||
keeper -> keeper : jail the validator, but proceed with unbonding | ||
note left : Default min delegation threshold : 1 share | ||
end | ||
|
||
database store | ||
|
||
alt complete unbonding, all shares removed | ||
keeper -> store : remove delegation object | ||
else there are still shares delegated (not a complete undbonding) | ||
keeper -> store : update delegation object | ||
keeper -> keeper : AfterDelegationModified hook | ||
end | ||
|
||
keeper -> store : update validator power index | ||
keeper -> store : update validator information (including token amount) | ||
|
||
alt validator status is "unbonded" and it has no more tokens | ||
keeper -> store : delete the validator | ||
note right : otherwise, do this in EndBlock once validator is unbonded | ||
end | ||
end | ||
|
||
alt validator is bonded | ||
keeper -> bankKeeper : send tokens from bonded pool to not bonded pool | ||
end | ||
|
||
msgServer -> msgServer : emit event : EventTypeUnbond(delAddr, valAddr, tokenAmount, completion time) | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hjorthjort could you add a way to generate the plantuml? This is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marbar3778 Can you elaborate on "a way to generate the plantuml"? We need a plantuml binary to generate diagrams. By far the least hairy way would be to install it as a package from the standard package manager. Is it not available?
The other options are building it from source (hairier) or committing the official
.jar
directly, which would not stay up to date. The.jar
option might be best if we can't install the package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to do something like this: https://github.com/miy4/docker-plantuml/blob/master/Dockerfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you were trying to generate the uml files for useage in docs. This was failing because there is no uml binary. Is it okay we just dont generated the uml files into something that can be rendered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also possible to just generate the files locally (by anyone who has plantuml) and we simply commit the files. Not having them in the docs at all seems like a big step back, they are there to clarify things and there seemed to be a lot of positive feedback on having them.
But it's up to you what you think is the most hygenic approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can generate them locally and push them. Could you do this? I dont see us changing these files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay. can you update your open PR to remove the plantuml from the Dockerfile and remove (instead of commenting out) the line for generating them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be solved by #9124 (comment)