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

WIP Relayer for Solana #439

Draft
wants to merge 260 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
260 commits
Select commit Hold shift + click to select a range
f6b5f9f
added query channel, connection and proofs
dhruvja Oct 27, 2023
a7bbc60
added few more query methods
dhruvja Oct 27, 2023
eee35f5
replace sealable trie packages with public repo
dhruvja Oct 29, 2023
0bfdae0
added channel whitelist
dhruvja Oct 30, 2023
63e221a
added query for unreceived acks and packets
dhruvja Oct 30, 2023
1e845f8
updated trie_key and added ids
dhruvja Nov 20, 2023
2306e66
fix connectionId issue
dhruvja Nov 21, 2023
7187ec2
added chain and packet accounts
dhruvja Nov 21, 2023
1616fbb
updated storage and methods and added duplicate ibc dep
dhruvja Nov 22, 2023
87f1058
added methods and conversions
dhruvja Dec 5, 2023
b67b6f9
refactor
dhruvja Dec 5, 2023
e73abd2
converting client and consensus state and added method to get latest …
dhruvja Dec 6, 2023
2a5d6a1
added type conversions for messages
dhruvja Dec 7, 2023
a63137b
fixed issues and added few methods
dhruvja Dec 7, 2023
1665409
added recv and send packets
dhruvja Dec 11, 2023
eddbcee
querying finality notifications
dhruvja Dec 11, 2023
afe4c6e
setup tests for solana cosmos
dhruvja Dec 11, 2023
43c45fe
added mocks along with initialize client state method
dhruvja Dec 12, 2023
4fd9e84
added query connection channels
dhruvja Dec 12, 2023
003f021
test config and async sol program
dhruvja Dec 13, 2023
9d0642f
added spawn blocking for sol rpc client
dhruvja Dec 14, 2023
d39dc16
testing wip
dhruvja Dec 17, 2023
9bb6b7e
fix sync and fmt
dhruvja Dec 18, 2023
fb4c49f
wip
dhruvja Dec 18, 2023
00acd2e
wip
dhruvja Dec 19, 2023
02ed256
wip
dhruvja Dec 20, 2023
88128f8
add mock solana light client
dhruvja Dec 21, 2023
5578e26
fixed issues for token transfer
dhruvja Jan 2, 2024
2d57d61
added send transfer
dhruvja Jan 4, 2024
4901d83
changed rpc for devnet and added retry logic
dhruvja Jan 18, 2024
b5f8792
added docs for running solana cosmos tests locally
dhruvja Jan 18, 2024
d7aa062
adding branch info in instructions
dhruvja Jan 18, 2024
53f0e44
fix issues with url and added instruction to compile wasm
dhruvja Jan 19, 2024
a182a2a
use git deps and retry tx logic
dhruvja Jan 25, 2024
d7ff1cc
Fix overflow (#464)
vmarkushin Dec 19, 2023
976bfc9
Cosmos fixes and improvements; metric handling fix (#474)
vmarkushin Feb 9, 2024
e258cc9
Update Cargo.lock
vmarkushin Feb 9, 2024
1c4a6bb
Update Cargo.lock
vmarkushin Feb 9, 2024
47d6ee0
subxt update (#462)
kkast Dec 19, 2023
d775eb6
subxt update (#466)
kkast Dec 27, 2023
19a0e26
added chunking and upgraded dependencies
dhruvja Feb 23, 2024
4c8c6e0
added method for signature verification and deliver with accounts
dhruvja Feb 29, 2024
ec24275
wip
mina86 Mar 3, 2024
64cbe06
call deliver with account when message is received
dhruvja Mar 4, 2024
df7f81a
remove redundant files in hyperspace/solana
dhruvja Mar 4, 2024
a3bd718
clean up and remove unused vars
dhruvja Mar 4, 2024
e5a45d1
moved general methods to utils file
dhruvja Mar 4, 2024
1c66e3e
fmt
dhruvja Mar 4, 2024
c442f0e
check receiver chain and source and perform transfer
dhruvja Mar 4, 2024
802d49f
fix send transfer logic
dhruvja Mar 4, 2024
5aff3ba
wip
mina86 Mar 4, 2024
14a8d75
wip
mina86 Mar 5, 2024
a829c5e
wip
mina86 Mar 5, 2024
6d3e9bd
use types crate from lts ibc
dhruvja Mar 5, 2024
54e39cc
wip
mina86 Mar 5, 2024
8e746e7
fmt
mina86 Mar 5, 2024
246855f
review
mina86 Mar 5, 2024
be8ec1b
update dep
mina86 Mar 7, 2024
bbae5fd
rm unneccesary code
dhruvja Mar 7, 2024
596ef1f
pull from upstream
dhruvja Mar 8, 2024
0667cf9
Update light-clients/cf-guest-cw/Cargo.toml
mina86 Mar 8, 2024
06902a9
wip
mina86 Mar 8, 2024
2cfd17e
wip
mina86 Mar 8, 2024
c574456
Merge branch 'a' of https://github.com/mina86/composable-ibc into hyp…
dhruvja Mar 8, 2024
c07338e
added guest-chain light client
dhruvja Mar 11, 2024
2a60fd8
implemented custom errors
dhruvja Mar 11, 2024
dd8252b
implement verification in clientdef trait
dhruvja Mar 11, 2024
82767b1
add guest client to light client
dhruvja Mar 11, 2024
0445be9
fix prootbuf derive
mina86 Mar 11, 2024
e01b6b3
fix to threadsafe
mina86 Mar 11, 2024
3d8b59b
deps
mina86 Mar 11, 2024
d821943
implement old ibc for cf-guest-cw
dhruvja Mar 12, 2024
5fcb865
impl anyclientstate proto
dhruvja Mar 13, 2024
1ecff56
Revert "Contract updates addressing the ibc-go wasm light client refa…
dhruvja Mar 13, 2024
2556c50
wip
dhruvja Mar 13, 2024
fcb6180
change contract interface
mina86 Mar 13, 2024
e328ea8
deps
mina86 Mar 13, 2024
6aa1b17
wip
mina86 Mar 14, 2024
fed2e67
wasm state
mina86 Mar 14, 2024
b952e90
wip
dhruvja Mar 14, 2024
165c1cb
update cosmwasm contract
dhruvja Mar 14, 2024
e5856e8
added unit test for testing client message payload
dhruvja Mar 15, 2024
e1e4946
fixed consensus state decoding
dhruvja Mar 15, 2024
9eee178
update cosmwasm
dhruvja Mar 15, 2024
5a2309d
implement guest blockchain cw light client
blasrodri Mar 15, 2024
7b2b8f0
A (#484)
mina86 Mar 15, 2024
30789ef
validate-delay (#485)
mina86 Mar 15, 2024
bfa68d6
wasm from tm
dhruvja Mar 15, 2024
708080e
fix
dhruvja Mar 15, 2024
00f9c54
Fix inconsistencies and update dependencies
dhruvja Mar 21, 2024
17f9b07
small changes
dhruvja Mar 23, 2024
18b5bd7
fix updates in solana
dhruvja Mar 25, 2024
8802199
small changes
dhruvja Mar 29, 2024
78280a7
add signature chunking
dhruvja Mar 30, 2024
88fd7b4
minor changes
dhruvja Apr 6, 2024
b1948bf
update deps
dhruvja Apr 8, 2024
c3347c8
fix ibc testkit
dhruvja Apr 8, 2024
ef4ad96
creating new connection in tests
dhruvja Apr 8, 2024
3af7873
filter events
dhruvja Apr 8, 2024
3d50c24
use arc mutex in solana client config
dhruvja Apr 8, 2024
76317e2
add config for solana and replace pubkey with string
dhruvja Apr 18, 2024
3fb9874
use latest version of solana ibc
dhruvja Apr 18, 2024
253582d
update ibc rev
dhruvja Apr 19, 2024
c31eecc
Update guestchain dependencies (#492)
mina86 Apr 22, 2024
54340d3
ics02: fix error message when decoding consensus state
mina86 Apr 23, 2024
16e0430
ics02: fix formatting
mina86 Apr 23, 2024
215a808
hyperspace-core: fix testing feature
mina86 Apr 23, 2024
286dca8
pallet-ibc: use type URLs from upstream rather than redefining
mina86 Apr 23, 2024
f1af1a8
cf-guest: fix Protobuf implementation
mina86 Apr 23, 2024
fb1e2cd
icsxx-solana-cw: remove unused crate (#493)
mina86 Apr 23, 2024
7575ef3
Update emulated-light-client dependency
mina86 Apr 23, 2024
86d782b
add localnet config
dhruvja Apr 24, 2024
6c71370
Merge branch 'hyperspace-solana' of https://github.com/ComposableFi/c…
dhruvja Apr 24, 2024
585ea8a
fix relayer bugs and improve fetching events
dhruvja Apr 25, 2024
60e224e
fix timeouts
dhruvja Apr 25, 2024
8975fe0
updated structures and fixed bugs
dhruvja Apr 27, 2024
c6a4bc7
send user account during ack
dhruvja Apr 28, 2024
75b394f
increase trusting period
dhruvja Apr 28, 2024
a50fea9
convert signer to string
dhruvja Apr 28, 2024
9d89207
use height as never if rev no. is 0
dhruvja Apr 28, 2024
09f7077
use commitment for query packet acknowledgements
dhruvja Apr 28, 2024
b432c7a
fetch unreceived acks from commitments
dhruvja Apr 28, 2024
2cbbd2b
use token account from packet
dhruvja Apr 29, 2024
c729e0f
receiver should be token account owner
dhruvja Apr 29, 2024
376341e
check token account on chain
dhruvja Apr 29, 2024
c7c40ec
get rid of panics
dhruvja Apr 30, 2024
a9ca328
fix seeds
dhruvja May 1, 2024
7932fe3
some changes form vm
May 1, 2024
8685e43
fix merge conflicts
May 1, 2024
250c6e9
fix issues while receiving
dhruvja May 1, 2024
e2859ba
fix all merge conflicts
dhruvja May 1, 2024
b1db631
update timeouts
dhruvja May 1, 2024
c98dd22
avoid unwrap
dhruvja May 1, 2024
15810de
panic when disconnects
dhruvja May 1, 2024
a4adfbe
make cosmos bullish again
dhruvja May 1, 2024
d590ed4
fetch all the packets for recv and send
dhruvja May 1, 2024
202f3e5
logs
dhruvja May 1, 2024
9cdf6ea
remove block header getter in query proof
dhruvja May 1, 2024
cba6912
use block header og
dhruvja May 1, 2024
081968a
testing proof height
dhruvja May 1, 2024
9c6ae71
use lts height on source
dhruvja May 1, 2024
91dc30b
loop when submitting the update
dhruvja May 2, 2024
b8c15ed
fix infinite loop
dhruvja May 2, 2024
b839bc6
import duration
dhruvja May 2, 2024
f46cca9
add semicolon
dhruvja May 2, 2024
4195510
get timeout height
dhruvja May 2, 2024
0c466bf
upgrade solana-ibc
dhruvja May 2, 2024
3753acb
logs
dhruvja May 2, 2024
4ed1fec
rm unneccesary logging
dhruvja May 2, 2024
487bbf5
add timeout height as never if revision number is 0
dhruvja May 2, 2024
c56718a
optimize
dhruvja May 3, 2024
cd95a48
parallelize signature tx
dhruvja May 3, 2024
dab6ea1
add signer
dhruvja May 3, 2024
67b09a6
rm sig parallel
dhruvja May 3, 2024
8b3a2d0
remove proof heights from channel end and connection end
dhruvja May 3, 2024
c9554d5
dont process all send or ack packets
dhruvja May 3, 2024
0b32aa6
current block header for client state
dhruvja May 3, 2024
c601d50
make updates in ascending
dhruvja May 3, 2024
0216dab
initialize client state using latest blockhash
dhruvja May 5, 2024
dd60b26
epoch with all validators and index based on that
dhruvja May 6, 2024
befc973
send mandatory update when epoch changes
dhruvja May 6, 2024
4d3b177
send updates every interval
dhruvja May 6, 2024
db81e7d
get proof height for timeout
dhruvja May 6, 2024
c3c8f8b
fmt
dhruvja May 6, 2024
94ec676
fix checking if channels are created
dhruvja May 6, 2024
40f164e
add flag for handshake completed
dhruvja May 6, 2024
b8caee0
add solana mainnet config
dhruvja May 6, 2024
b319383
parallelize transactions
dhruvja May 7, 2024
165aa4d
chuking for all tx
dhruvja May 7, 2024
498af52
remove calling client update method
dhruvja May 7, 2024
0355cec
fix time since last update
dhruvja May 7, 2024
7b69379
add jito and batch all tx
dhruvja May 8, 2024
db49043
update dep of jito
dhruvja May 8, 2024
a1ffbb1
revert local path change
dhruvja May 8, 2024
fff3f5d
fix skipping for open init channel
dhruvja May 8, 2024
e729a4a
remove handshake complete
dhruvja May 8, 2024
9074ecc
add handshake flag
dhruvja May 8, 2024
528efd1
clear unneccesary things
dhruvja May 8, 2024
d4a814a
fix handshake completed
dhruvja May 8, 2024
6b865dd
retry when fetching logs
dhruvja May 8, 2024
3822a97
remove mainnet configs
dhruvja May 8, 2024
33b965a
cf-guest: update upstream dependency (#495)
mina86 May 9, 2024
d0ac775
merge from solana-fees-token-mint branch
dhruvja May 9, 2024
e73fd42
fix epoch and merge from solana-fees-token-mint branch
dhruvja May 9, 2024
202e2ad
revert toolchain version
dhruvja May 9, 2024
085745b
reversing updates to be sent on cosmos
dhruvja May 9, 2024
2002455
send multiple client update only to cosmos from solana
dhruvja May 9, 2024
3288595
error handling while fetching events
dhruvja May 9, 2024
ee1df86
run single cosmos tx
dhruvja May 9, 2024
706dda2
use epoch commitment instead of epoch id
dhruvja May 9, 2024
c45d02e
send update during epoch change
dhruvja May 9, 2024
2ac70fb
skip only optional updates
dhruvja May 9, 2024
c011570
change tx type to jito and trusting period to 640000
dhruvja May 10, 2024
59a01fb
fix issue with earliest block header in solana
dhruvja May 10, 2024
5baf6ac
uncomment all signatures in solana
dhruvja May 10, 2024
8341210
fix mandatory updates
dhruvja May 10, 2024
553c584
sleep during updates
dhruvja May 10, 2024
24d397f
fix sleep
dhruvja May 10, 2024
da07e7c
default update height to 0
dhruvja May 10, 2024
5ba9765
logs for proofs
dhruvja May 10, 2024
016077f
fix
dhruvja May 10, 2024
5c96c5b
show proof at different height
dhruvja May 10, 2024
e5c1c23
increase CU for sigverify
dhruvja May 10, 2024
4446085
get trie data from db
dhruvja May 10, 2024
1938d15
fix query proofs
dhruvja May 10, 2024
6698cdb
use jito
dhruvja May 10, 2024
7868c12
log trie root
dhruvja May 10, 2024
fba4967
fix bug
dhruvja May 10, 2024
b97cd97
return latest trie if trie doesnt exist in indexer
dhruvja May 11, 2024
4318b0b
process packets in chunks
dhruvja May 11, 2024
cb578d2
add trie db path in config
dhruvja May 12, 2024
5983613
fix trie fetch
dhruvja May 12, 2024
252b0e4
fetch block header only when proof matches
dhruvja May 12, 2024
e9879c9
simulate tx
dhruvja May 13, 2024
9f67610
remove simulation
dhruvja May 13, 2024
036bcf7
log encoded transactions
dhruvja May 13, 2024
68655f8
logging signed tx
dhruvja May 13, 2024
7d5833c
log encoded tx of all tx
dhruvja May 13, 2024
e5a5650
increase heap
dhruvja May 13, 2024
ec7c323
chunk only once
dhruvja May 13, 2024
ad2b0c0
fix ack
dhruvja May 13, 2024
75d956a
increase chunk size to 4
dhruvja May 13, 2024
cf78efb
dont add trace prefix
dhruvja May 16, 2024
ba88365
add trace prefix only for recv
dhruvja May 17, 2024
55a34e7
uncomment get trie
dhruvja May 17, 2024
1b49449
dont fetch sequences if they are higher
dhruvja May 21, 2024
4461fee
skip if maximum sequence is found
dhruvja May 21, 2024
a9acae1
use dep from git instead of locally
dhruvja May 24, 2024
2dbd4f8
fetch validators from epoch
dhruvja May 25, 2024
dea9a6a
prevent repetitive client updates
dhruvja May 25, 2024
ce3eae3
not fetch ready packets
dhruvja May 25, 2024
91be5b9
fix
dhruvja May 25, 2024
aa31749
fix
dhruvja May 25, 2024
65607e5
test
dhruvja May 25, 2024
bbd2b16
revert test changes
dhruvja May 25, 2024
2c10acb
improve logging
dhruvja May 29, 2024
e96d261
add migrate entrypoint to cw contract
dhruvja May 31, 2024
71c3ee3
search ibc events using storage instead of program id
dhruvja May 31, 2024
ea1592c
reduce jito fees
dhruvja Jun 2, 2024
20891ca
Contract updates addressing the ibc-go wasm light client refactoring …
misko9 Dec 15, 2023
ddb0c70
reducing fees and skipping tx which are errored
dhruvja Jun 10, 2024
ba5b179
use finalized for getting finality notifications
dhruvja Jun 10, 2024
3ae10e9
remove priority fees
dhruvja Jun 10, 2024
8956e4d
change solana block time to 0
dhruvja Jun 25, 2024
17b2a0f
Copy `cf-guest` -> `icsxx-cf-solana`
vmarkushin Jul 17, 2024
bd05fde
update tm and port cf-guest to sdk50
dhruvja Aug 1, 2024
299045c
port to sdk50
dhruvja Aug 7, 2024
8c86ba9
use local deps
dhruvja Aug 16, 2024
8634300
wip
dhruvja Aug 16, 2024
20e99e5
fix sdk 50
dhruvja Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,031 changes: 3,131 additions & 900 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
"hyperspace/primitives",
"hyperspace/parachain",
"hyperspace/cosmos",
"hyperspace/solana",
"hyperspace/testsuite",
"hyperspace/metrics",

Expand All @@ -53,6 +54,10 @@ members = [
[patch."https://github.com/paritytech/jsonrpsee"]
jsonrpsee = { version = "0.16.3" }

[patch.crates-io]
aes-gcm-siv = { git = "https://github.com/dhruvja/AEADs", branch = "main-aes-gcm-siv-v0.10.3" }
curve25519-dalek = { git = "https://github.com/dhruvja/curve25519-dalek", branch = "master" }

[patch."https://github.com/paritytech/substrate"]
sc-executor = { git = "https://github.com/paritytech//substrate.git", branch = "polkadot-v0.9.43" }
sc-executor-common = { git = "https://github.com/paritytech//substrate.git", branch = "polkadot-v0.9.43" }
Expand Down
79 changes: 79 additions & 0 deletions hyperspace/solana/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[package]
name = "hyperspace-solana"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
primitives = { path = "../primitives", package = "hyperspace-primitives" }

# crates.io
anyhow = "1.0.65"
futures = "0.3.21"
async-trait = "0.1.53"
log = "0.4.17"
hex = "0.4.3"
tokio = { version = "1.32.0", features = ["macros", "sync"] }
rs_merkle = "1.2.0"
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
serde_json = "1.0.74"
derive_more = { version = "0.99", features = ["from"] }
serde = {version="1.0.137", features = ["derive"]}
tokio-stream = { version = "0.1.14", features = ["sync"]}
thiserror = "1.0.31"
itertools = "0.10.3"
prost = { version = "0.11" }
k256 = { version = "0.11.6", features = ["ecdsa-core", "ecdsa", "sha256"] }
tonic = { version = "0.8", features = ["tls", "tls-roots"] }
bech32 = "0.9.1"
bip32 = "0.4.0"
ed25519-zebra = { version = "3.1.0" }
tiny-bip39 = "1.0.0"
sha2 = "0.10.6"
ripemd = "0.1.3"
digest = "0.10.6"
quick_cache = "0.3.0"
rand = "0.8.5"
anchor-client = "0.28.0"
anchor-lang = "0.28.0"
borsh = { version = "0.10.3", default-features = false }

# composable
ibc = { path = "../../ibc/modules", features = [] }
ibc-proto = { path = "../../ibc/proto" }
ibc-primitives = { path = "../../contracts/pallet-ibc/primitives" }
ics07-tendermint = { path = "../../light-clients/ics07-tendermint" }
ics08-wasm = { path = "../../light-clients/ics08-wasm" }
ibc-rpc = { path = "../../contracts/pallet-ibc/rpc" }
pallet-ibc = { path = "../../contracts/pallet-ibc" }

# Trie
lib = { git = "https://github.com/ComposableFi/emulated-light-client.git" }
memory = { git = "https://github.com/ComposableFi/emulated-light-client.git" }
sealable-trie = { git = "https://github.com/ComposableFi/emulated-light-client.git", features = ["borsh"] }
stdx = { git = "https://github.com/ComposableFi/emulated-light-client.git" }

tracing = "0.1.36"

# tendermint
tendermint = { git = "https://github.com/informalsystems/tendermint-rs", rev = "e81f7bf23d63ffbcd242381d1ce5e35da3515ff1", default-features = false, features = [
"secp256k1",
] }
tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", rev = "e81f7bf23d63ffbcd242381d1ce5e35da3515ff1", default-features = false }
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", rev = "e81f7bf23d63ffbcd242381d1ce5e35da3515ff1", default-features = false, features = [
"http-client",
"websocket-client",
] }
tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs", rev = "e81f7bf23d63ffbcd242381d1ce5e35da3515ff1", default-features = false, features = [
"rpc-client",
"secp256k1",
"unstable",
# "testing"
] }
tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs", rev = "e81f7bf23d63ffbcd242381d1ce5e35da3515ff1", default-features = false }

[features]
testing = [
"primitives/testing"
]
40 changes: 40 additions & 0 deletions hyperspace/solana/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use anchor_client::anchor_lang::prelude::*;

/// Accounts required for calling the deliver method on smart contract
pub struct LocalDeliver {
dhruvja marked this conversation as resolved.
Show resolved Hide resolved
/// Signer
pub sender: AccountMeta,
/// Storage Account for all the IBC data
pub storage: AccountMeta,
/// Sealable trie which stores the proof
pub trie: AccountMeta,
/// System Program (`11111111111111111111111111111111`) used to create the above 2 accounts if
/// not already created
pub system_program: AccountMeta,
}

impl LocalDeliver {
pub fn new(
sender_key: Pubkey,
storage_key: Pubkey,
trie_key: Pubkey,
system_program_key: Pubkey,
) -> Self {
let sender = AccountMeta::new(sender_key, true);
let storage = AccountMeta::new(storage_key, false);
let trie = AccountMeta::new(trie_key, false);
let system_program = AccountMeta::new_readonly(system_program_key, false);
Self { sender, storage, trie, system_program }
}
}

impl ToAccountMetas for LocalDeliver {
fn to_account_metas(&self, _is_signer: Option<bool>) -> Vec<AccountMeta> {
let mut accounts = Vec::new();
accounts.push(self.sender.clone());
accounts.push(self.storage.clone());
accounts.push(self.trie.clone());
accounts.push(self.system_program.clone());
accounts
}
}
Empty file added hyperspace/solana/src/client.rs
Empty file.
34 changes: 34 additions & 0 deletions hyperspace/solana/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use ibc::timestamp::ParseTimestampError;
use prost::DecodeError;

/// Error definitions for the cosmos client in accordance with the parachain's Error type.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// An error from the rpc interface
#[error("Rpc client error: {0}")]
RpcError(String),
/// Custom error
#[error("{0}")]
Custom(String),
/// Decode error
#[error("Decode error: {0}")]
DecodeError(#[from] DecodeError),
/// Encode error
#[error("Encode error: {0}")]
EncodeError(#[from] prost::EncodeError),
/// Parse timestamp error
#[error("Parse timestamp error: {0}")]
ParseTimestampError(#[from] ParseTimestampError),
/// Transfer error
#[error("IBC transfer error: {0}")]
TransferError(#[from] ibc::applications::transfer::error::Error),
/// Tendermint error
#[error("Tendermint error: {0}")]
TendermintError(#[from] tendermint::Error),
}

impl From<String> for Error {
fn from(error: String) -> Self {
Self::Custom(error)
}
}
109 changes: 109 additions & 0 deletions hyperspace/solana/src/ibc_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use alloc::collections::BTreeMap;
use anchor_lang::prelude::*;
use borsh::{BorshDeserialize, BorshSerialize};
use ibc::core::ics04_channel::packet::Sequence;

pub type InnerHeight = (u64, u64);
pub type HostHeight = InnerHeight;
pub type SolanaTimestamp = u64;
pub type InnerClientId = String;
pub type InnerConnectionId = String;
pub type InnerPortId = String;
pub type InnerChannelId = String;
pub type InnerSequence = u64;
pub type InnerIbcEvent = Vec<u8>;
pub type InnerClient = String; // Serialized
pub type InnerConnectionEnd = String; // Serialized
pub type InnerChannelEnd = String; // Serialized
pub type InnerConsensusState = String; // Serialized

/// A triple of send, receive and acknowledge sequences.
#[derive(Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct InnerSequenceTriple {
sequences: [u64; 3],
mask: u8,
}

#[derive(Clone, Copy)]
pub enum SequenceTripleIdx {
Send = 0,
Recv = 1,
Ack = 2,
}

impl InnerSequenceTriple {
/// Returns sequence at given index or `None` if it wasn’t set yet.
pub fn get(&self, idx: SequenceTripleIdx) -> Option<Sequence> {
if self.mask & (1 << (idx as u32)) == 1 {
Some(Sequence::from(self.sequences[idx as usize]))
} else {
None
}
}

/// Sets sequence at given index.
pub fn set(&mut self, idx: SequenceTripleIdx, seq: Sequence) {
self.sequences[idx as usize] = u64::from(seq);
self.mask |= 1 << (idx as u32)
}

/// Encodes the object as a `CryptoHash` so it can be stored in the trie
/// directly.
pub fn to_hash(&self) -> lib::hash::CryptoHash {
let mut hash = lib::hash::CryptoHash::default();
let (first, tail) = stdx::split_array_mut::<8, 24, 32>(&mut hash.0);
let (second, tail) = stdx::split_array_mut::<8, 16, 24>(tail);
let (third, tail) = stdx::split_array_mut::<8, 8, 16>(tail);
*first = self.sequences[0].to_be_bytes();
*second = self.sequences[1].to_be_bytes();
*third = self.sequences[2].to_be_bytes();
tail[0] = self.mask;
hash
}
}

// #[derive(Debug, AnchorSerialize, AnchorDeserialize)]
#[account]
/// All the structs from IBC are stored as String since they dont implement AnchorSerialize and
/// AnchorDeserialize
pub struct PrivateStorage {
pub height: InnerHeight,
pub clients: BTreeMap<InnerClientId, InnerClient>,
/// The client ids of the clients.
pub client_id_set: Vec<InnerClientId>,
pub client_counter: u64,
pub client_processed_times: BTreeMap<InnerClientId, BTreeMap<InnerHeight, SolanaTimestamp>>,
pub client_processed_heights: BTreeMap<InnerClientId, BTreeMap<InnerHeight, HostHeight>>,
pub consensus_states: BTreeMap<(InnerClientId, InnerHeight), InnerConsensusState>,
/// This collection contains the heights corresponding to all consensus states of
/// all clients stored in the contract.
pub client_consensus_state_height_sets: BTreeMap<InnerClientId, Vec<InnerHeight>>,
/// The connection ids of the connections.
pub connection_id_set: Vec<InnerConnectionId>,
pub connection_counter: u64,
pub connections: BTreeMap<InnerConnectionId, InnerConnectionEnd>,
pub channel_ends: BTreeMap<(InnerPortId, InnerChannelId), InnerChannelEnd>,
// Contains the client id corresponding to the connectionId
pub connection_to_client: BTreeMap<InnerConnectionId, InnerClientId>,
/// The port and channel id tuples of the channels.
pub port_channel_id_set: Vec<(InnerPortId, InnerChannelId)>,
pub channel_counter: u64,

/// Next send, receive and ack sequence for given (port, channel).
///
/// We’re storing all three sequences in a single object to reduce amount of
/// different maps we need to maintain. This saves us on the amount of
/// trie nodes we need to maintain.
pub next_sequence: BTreeMap<(InnerPortId, InnerChannelId), InnerSequenceTriple>,

/// The sequence numbers of the packet commitments.
pub packet_commitment_sequence_sets:
BTreeMap<(InnerPortId, InnerChannelId), Vec<InnerSequence>>,
/// The sequence numbers of the packet receipts.
pub packet_receipt_sequence_sets: BTreeMap<(InnerPortId, InnerChannelId), Vec<InnerSequence>>,
/// The sequence numbers of the packet acknowledgements.
pub packet_acknowledgement_sequence_sets:
BTreeMap<(InnerPortId, InnerChannelId), Vec<InnerSequence>>,
/// The history of IBC events.
pub ibc_events_history: BTreeMap<InnerHeight, Vec<InnerIbcEvent>>,
}
19 changes: 19 additions & 0 deletions hyperspace/solana/src/instructions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use anchor_client::{anchor_lang, anchor_lang::prelude::*};

#[derive(Debug, Clone, PartialEq, AnchorSerialize, AnchorDeserialize)]
/// Arguments to the instruction
pub struct Deliver {
pub messages: Vec<AnyCheck>,
}

/// 8 byte unique identifier for Deliver Type
impl anchor_lang::Discriminator for Deliver {
const DISCRIMINATOR: [u8; 8] = [250, 131, 222, 57, 211, 229, 209, 147];
}
impl anchor_lang::InstructionData for Deliver {}

#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, PartialEq)]
pub struct AnyCheck {
pub type_url: String,
pub value: Vec<u8>,
}
Loading