1
- ----------------------------- MODULE ICS20Chain -----------------------------
1
+ ------------------------------- MODULE Chain -- -----------------------------
2
2
3
- EXTENDS Integers , FiniteSets , Sequences , ICS20Definitions , PacketHandlers ,
4
- FungibleTokenTransferHandlers
3
+ EXTENDS Integers , FiniteSets , Sequences , IBCTokenTransferDefinitions ,
4
+ ICS04PacketHandlers , ICS20FungibleTokenTransferHandlers
5
5
6
6
CONSTANTS MaxHeight , \* maximal chain height
7
7
MaxPacketSeq , \* maximal packet sequence number
@@ -14,45 +14,45 @@ VARIABLES chainStore, \* chain store, containing client heights, a connection en
14
14
incomingPacketDatagrams , \* sequence of incoming packet datagrams
15
15
appPacketSeq , \* packet sequence number from the application on the chain
16
16
packetLog , \* packet log
17
- accounts \* a map from chainIDs and denominations to account balances
17
+ accounts , \* a map from chainIDs and denominations to account balances
18
+ escrowAccounts \* a map from channelIDs and denominations to escrow account balances
18
19
19
20
20
21
vars == << chainStore , incomingPacketDatagrams , appPacketSeq ,
21
- packetLog , accounts >>
22
+ packetLog , accounts , escrowAccounts >>
22
23
Heights == 1 .. MaxHeight \* set of possible heights of the chains in the system
23
24
24
25
(* **************************************************************************
25
26
Token transfer operators
26
27
************************************************************************** *)
27
- \* Create a packet: Abstract away from ports, and timestamp.
28
+ \* Create a packet: Abstract away from timestamp.
28
29
\* Assume timeoutHeight is MaxHeight + 1
29
30
CreatePacket ( packetData ) ==
30
31
AsPacket ( [
31
32
sequence |-> appPacketSeq ,
32
33
timeoutHeight |-> MaxHeight + 1 ,
33
34
data |-> packetData ,
34
35
srcChannelID |-> GetChannelID ( ChainID ) ,
35
- dstChannelID |-> GetChannelID ( GetCounterpartyChainID ( ChainID ) )
36
+ srcPortID |-> GetPortID ( ChainID ) ,
37
+ dstChannelID |-> GetCounterpartyChannelID ( ChainID ) ,
38
+ dstPortID |-> GetCounterpartyPortID ( ChainID )
36
39
] )
37
-
38
- \* update packet committments and escrow accounts in the chain store
39
- UpdatePacketCommitmentsAndEscrowAcounts ( chain , packet , escrowAccounts ) ==
40
- \* write packet committment
41
- LET writtenCommittmentStore == WritePacketCommitment ( chain , packet ) IN
42
- \* update escrow accounts
43
- [ writtenCommittmentStore EXCEPT ! . escrowAccounts = escrowAccounts ]
44
-
40
+
45
41
46
42
\* Update the chain store and packet log with ICS20 packet datagrams
47
43
TokenTransferUpdate ( chainID , packetDatagram , log ) ==
48
44
LET packet == packetDatagram . packet IN
49
45
\* get the new updated store, packet log, and accounts
50
46
LET tokenTransferUpdate ==
51
47
IF packetDatagram . type = "PacketRecv"
52
- THEN HandlePacketRecv ( chainID , chainStore , packetDatagram , log , accounts )
48
+ THEN HandlePacketRecv ( chainID , chainStore , packetDatagram , log , accounts , escrowAccounts , MaxBalance )
53
49
ELSE IF packetDatagram . type = "PacketAck"
54
- THEN HandlePacketAck ( chainID , chainStore , packetDatagram , log , accounts )
55
- ELSE [ store |-> chainStore , log |-> log , accounts |-> accounts ] IN
50
+ THEN HandlePacketAck ( chainStore , packetDatagram , log , accounts , escrowAccounts , MaxBalance )
51
+ ELSE [ store |-> chainStore ,
52
+ log |-> log ,
53
+ accounts |-> accounts ,
54
+ escrowAccounts |-> escrowAccounts ]
55
+ IN
56
56
57
57
LET tokenTransferStore == tokenTransferUpdate . store IN
58
58
@@ -65,7 +65,8 @@ TokenTransferUpdate(chainID, packetDatagram, log) ==
65
65
66
66
[ store |-> updatedStore ,
67
67
log |-> tokenTransferUpdate . log ,
68
- accounts |-> tokenTransferUpdate . accounts ]
68
+ accounts |-> tokenTransferUpdate . accounts ,
69
+ escrowAccounts |-> tokenTransferUpdate . escrowAccounts ]
69
70
70
71
(* **************************************************************************
71
72
Chain actions
@@ -74,7 +75,8 @@ TokenTransferUpdate(chainID, packetDatagram, log) ==
74
75
AdvanceChain ==
75
76
/\ chainStore . height + 1 \in Heights
76
77
/\ chainStore ' = [ chainStore EXCEPT ! . height = chainStore . height + 1 ]
77
- /\ UNCHANGED << incomingPacketDatagrams , appPacketSeq , packetLog , accounts >>
78
+ /\ UNCHANGED << incomingPacketDatagrams , appPacketSeq , packetLog >>
79
+ /\ UNCHANGED << accounts , escrowAccounts >>
78
80
79
81
\* handle the incoming packet datagrams
80
82
HandlePacketDatagrams ==
@@ -84,6 +86,7 @@ HandlePacketDatagrams ==
84
86
/\ chainStore ' = tokenTransferUpdate . store
85
87
/\ packetLog ' = tokenTransferUpdate . log
86
88
/\ accounts ' = tokenTransferUpdate . accounts
89
+ /\ escrowAccounts ' = tokenTransferUpdate . escrowAccounts
87
90
/\ incomingPacketDatagrams ' = Tail ( incomingPacketDatagrams )
88
91
/\ UNCHANGED appPacketSeq
89
92
@@ -94,7 +97,7 @@ SendPacket ==
94
97
\* Create packet data
95
98
/\ LET createOutgoingPacketOutcome ==
96
99
CreateOutgoingPacketData ( accounts ,
97
- chainStore . escrowAccounts ,
100
+ escrowAccounts ,
98
101
<< NativeDenomination >> ,
99
102
MaxBalance ,
100
103
ChainID ,
@@ -106,8 +109,7 @@ SendPacket ==
106
109
\/ /\ ~ createOutgoingPacketOutcome . error
107
110
/\ LET packet == CreatePacket ( createOutgoingPacketOutcome . packetData ) IN
108
111
\* update chain store with packet committment
109
- /\ chainStore ' = UpdatePacketCommitmentsAndEscrowAcounts (
110
- chainStore , packet , createOutgoingPacketOutcome . escrowAccounts )
112
+ /\ chainStore ' = WritePacketCommitment ( chainStore , packet )
111
113
\* log sent packet
112
114
/\ packetLog ' = Append ( packetLog ,
113
115
AsPacketLogEntry (
@@ -119,6 +121,8 @@ SendPacket ==
119
121
) )
120
122
\* update bank accounts
121
123
/\ accounts ' = createOutgoingPacketOutcome . accounts
124
+ \* update escrow accounts
125
+ /\ escrowAccounts ' = createOutgoingPacketOutcome . escrowAccounts
122
126
\* increase application packet sequence
123
127
/\ appPacketSeq ' = appPacketSeq + 1
124
128
/\ UNCHANGED incomingPacketDatagrams
@@ -132,17 +136,17 @@ AcknowledgePacket ==
132
136
/\ chainStore ' = WriteAcknowledgement ( chainStore , Head ( chainStore . packetsToAcknowledge ) )
133
137
\* log acknowledgement
134
138
/\ packetLog ' = LogAcknowledgement ( ChainID , chainStore , packetLog , Head ( chainStore . packetsToAcknowledge ) )
135
- /\ UNCHANGED << incomingPacketDatagrams , accounts >>
136
- /\ UNCHANGED << appPacketSeq >>
139
+ /\ UNCHANGED << incomingPacketDatagrams , appPacketSeq >>
140
+ /\ UNCHANGED << accounts , escrowAccounts >>
137
141
138
142
(* **************************************************************************
139
143
Specification
140
144
************************************************************************** *)
141
145
\* Initial state predicate
142
146
\* Initially
143
- \* - the chain store is initialized to some element of the set
144
- \* ICS20InitChainStore(ChainID, NativeDenomination)
145
- \* (defined in ICS20Definitions .tla)
147
+ \* - the chain store is initialized to
148
+ \* ICS20InitChainStore(ChainID, << NativeDenomination>> )
149
+ \* (defined in IBCTokenTransferDefinitions .tla)
146
150
\* - incomingPacketDatagrams is an empty sequence
147
151
\* - the appPacketSeq is set to 1
148
152
Init ==
@@ -168,5 +172,5 @@ Fairness ==
168
172
169
173
=============================================================================
170
174
\* Modification History
171
- \* Last modified Fri Nov 06 20:27:05 CET 2020 by ilinastoilkovska
175
+ \* Last modified Fri Nov 20 16:09:50 CET 2020 by ilinastoilkovska
172
176
\* Created Mon Oct 17 13:01:03 CEST 2020 by ilinastoilkovska
0 commit comments