-
Notifications
You must be signed in to change notification settings - Fork 138
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
simibc: improves package documentation for simibc #662
Merged
+261
−163
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1c82e19
Starts on README
489df60
Adds README content
a24b789
Improves chain_util docstrings
b85bf00
Checkpoint pre revert chainID
60d9b3a
Revert to string in ordered link
485f2fe
Improves README
740ba39
Clarify chain util docstrings
288a919
Improves ordered link comments
c560e3b
Renames simibc ordered link to ordered outbox
bab8d21
Adds doc.go
ec9b28d
Bump OrderedOutbox
62bf4d9
Bump OrderedOutbox
4a1f51f
bump ordered outbox
48e4017
Bump ordered outbox
a590a53
Bump relay util
79975b4
Refactors relay
b8242f7
bump relay
95caf83
Bump many docstrings
ee9388a
Merge branch 'main' into danwt/simibc-clarity-improvements
danwt d61cf8a
Merge branch 'main' into danwt/simibc-clarity-improvements
shaspitz a5b78e3
fix ibc v3->v4 for new file
shaspitz 2d79af6
Merge branch 'main' into danwt/simibc-clarity-improvements
shaspitz ad41a87
solve merge conflicts
sainoe 9264934
Merge branch 'main' into danwt/simibc-clarity-improvements
shaspitz 3cbda42
Merge branch 'main' into danwt/simibc-clarity-improvements
sainoe 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
# simibc | ||
|
||
## What is this? | ||
|
||
A collection of utilities based on [ibc-go/testing](https://github.com/cosmos/ibc-go/tree/main/testing) which make it easier to write test scenarios involving precise orderings of | ||
|
||
- BeginBlock, EndBlock on each IBC connected chain | ||
- Packet delivery | ||
- Updating the client | ||
|
||
## Why is this useful? | ||
|
||
It is very hard to reason about tests written using vanilla [ibc-go/testing](https://github.com/cosmos/ibc-go/tree/main/testing) because the methods included in that library have many side effects. For example, that library has a notion of global time, so calling EndBlock on one chain will influence the future block times of another chain. As another example, sending a packet from chain A to B will automatically progress the block height on chain A. These behaviors make it very hard to understand, especially if your applications have business logic in BeginBlock or EndBlock. | ||
|
||
The utilities in simibc do not have any side effects, making it very easy to understand what is happening. It also makes it very easy to write data driven tests (like table tests, model based tests or property based tests). | ||
|
||
## How do I use this? | ||
|
||
Please see the function docstrings to get an idea of how you could use this package. This README is intentionally short because it is easier to maintain code and docstrings instead of markdown. |
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,4 @@ | ||
/* | ||
simibc is a collection of utilities wrapping the ibc-go testing framework which make is easier to write test scenarios involving precise orders of packet and ack delivery and calls to BeginBlock and EndBlock. | ||
*/ | ||
package simibc |
This file was deleted.
Oops, something went wrong.
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,114 @@ | ||
package simibc | ||
|
||
import channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" | ||
|
||
// Ack represents a (sent) ack committed to block state | ||
type Ack struct { | ||
Ack []byte | ||
// The packet to which this ack is a response | ||
Packet channeltypes.Packet | ||
// The number of App.Commits that have occurred since this ack was sent | ||
// For example, if the ack was sent at height h, and the blockchain | ||
// has headers ..., h, h+1, h+2 then Commits = 3 | ||
Commits int | ||
} | ||
|
||
// Packet represents a (sent) packet committed to block state | ||
type Packet struct { | ||
Packet channeltypes.Packet | ||
// The number of App.Commits that have occurred since this packet was sent | ||
// For example, if the ack was sent at height h, and the blockchain | ||
// has headers ..., h, h+1, h+2 then Commits = 3 | ||
Commits int | ||
} | ||
|
||
// OrderedOutbox is a collection of ORDERED packets and acks that have been sent | ||
// by different chains, but have not yet been delivered to their target. | ||
// The methods take care of bookkeeping, making it easier to simulate | ||
// a real relayed IBC connection. | ||
// | ||
// Each sent packet or ack can be added here. When a sufficient number of | ||
// block commits have followed each sent packet or ack, they can be consumed: | ||
// delivered to their target. Since the sequences are ordered, this is useful | ||
// for testing ORDERED ibc channels. | ||
// | ||
// NOTE: OrderedOutbox MAY be used independently of the rest of simibc. | ||
type OrderedOutbox struct { | ||
// An ordered sequence of packets from each sender | ||
OutboxPackets map[string][]Packet | ||
// An ordered sequence of acks from each sender | ||
OutboxAcks map[string][]Ack | ||
} | ||
|
||
// MakeOrderedOutbox creates a new empty OrderedOutbox. | ||
func MakeOrderedOutbox() OrderedOutbox { | ||
return OrderedOutbox{ | ||
OutboxPackets: map[string][]Packet{}, | ||
OutboxAcks: map[string][]Ack{}, | ||
} | ||
} | ||
|
||
// AddPacket adds an outbound packet from the sender. | ||
func (n OrderedOutbox) AddPacket(sender string, packet channeltypes.Packet) { | ||
n.OutboxPackets[sender] = append(n.OutboxPackets[sender], Packet{packet, 0}) | ||
} | ||
|
||
// AddAck adds an outbound ack from the sender. The ack is a response to the packet. | ||
func (n OrderedOutbox) AddAck(sender string, ack []byte, packet channeltypes.Packet) { | ||
n.OutboxAcks[sender] = append(n.OutboxAcks[sender], Ack{ack, packet, 0}) | ||
} | ||
|
||
// ConsumePackets returns the first num packets with 2 or more commits. Returned | ||
// packets are removed from the outbox and will not be returned again (consumed). | ||
func (n OrderedOutbox) ConsumePackets(sender string, num int) []Packet { | ||
ret := []Packet{} | ||
sz := len(n.OutboxPackets[sender]) | ||
if sz < num { | ||
num = sz | ||
} | ||
for _, p := range n.OutboxPackets[sender][:num] { | ||
if 1 < p.Commits { | ||
ret = append(ret, p) | ||
} else { | ||
break | ||
} | ||
} | ||
n.OutboxPackets[sender] = n.OutboxPackets[sender][len(ret):] | ||
return ret | ||
} | ||
|
||
// ConsumerAcks returns the first num packets with 2 or more commits. Returned | ||
// acks are removed from the outbox and will not be returned again (consumed). | ||
func (n OrderedOutbox) ConsumeAcks(sender string, num int) []Ack { | ||
ret := []Ack{} | ||
sz := len(n.OutboxAcks[sender]) | ||
if sz < num { | ||
num = sz | ||
} | ||
for _, a := range n.OutboxAcks[sender][:num] { | ||
if 1 < a.Commits { | ||
ret = append(ret, a) | ||
} else { | ||
break | ||
} | ||
} | ||
n.OutboxAcks[sender] = n.OutboxAcks[sender][len(ret):] | ||
return ret | ||
} | ||
|
||
// Commit marks a block commit, increasing the commit count for all | ||
// packets and acks in the sender's outbox. | ||
// When a packet or ack has 2 or more commits, it is available for | ||
// delivery to the counterparty chain. | ||
// Note that 2 commits are necessary instead of 1: | ||
// - 1st commit is necessary for the packet to included in the block | ||
// - 2nd commit is necessary because in practice the ibc light client | ||
// needs to have block h + 1 to be able to verify the packet in block h. | ||
func (n OrderedOutbox) Commit(sender string) { | ||
for i := range n.OutboxPackets[sender] { | ||
n.OutboxPackets[sender][i].Commits += 1 | ||
} | ||
for i := range n.OutboxAcks[sender] { | ||
n.OutboxAcks[sender][i].Commits += 1 | ||
} | ||
} |
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
Oops, something went wrong.
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.
@sainoe @MSalopek do we want to comment this out?
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.
Once that's decided, we're probably good to merge this one
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.
That will include the full
git diff
output at the header of thetraces.json
.It does seem like a nice feature, but I don't see a purpose of including the full diff inside a trace file. Commit hash should be enough and can be used to obtain a diff.