Skip to content

Commit

Permalink
fix: resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalden committed Dec 5, 2024
2 parents 1939a76 + 4a2503c commit 61dd932
Show file tree
Hide file tree
Showing 23 changed files with 1,285 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stellar-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79.0
toolchain: 1.81.0
target: wasm32-unknown-unknown
override: true
profile: minimal
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigInteger;

import score.ByteArrayObjectWriter;
import score.Context;
import score.ObjectReader;
import score.ObjectWriter;
Expand Down Expand Up @@ -66,8 +67,6 @@ public Packet(String srcNetwork, String srcContractAddress, BigInteger srcSn, Bi
|| srcHeight == null || dstNetwork == null || dstContractAddress == null || data == null;
Context.require(!isIllegalArg,
"srcNetwork, contractAddress, srcSn, srcHeight, dstNetwork, and data cannot be null");
if (isIllegalArg) {
}
this.srcNetwork = srcNetwork;
this.srcContractAddress = srcContractAddress;
this.srcSn = srcSn;
Expand All @@ -77,12 +76,8 @@ public Packet(String srcNetwork, String srcContractAddress, BigInteger srcSn, Bi
this.data = data;
}

public String getId() {
return createId(this.srcNetwork, this.srcContractAddress, this.srcSn);
}

public static String createId(String srcNetwork, String contractAddress, BigInteger srcSn) {
return srcNetwork + "/" + contractAddress + "/" + srcSn.toString();
public byte[] getId() {
return Context.hash("sha-256", this.toBytes());
}

/**
Expand Down Expand Up @@ -173,4 +168,10 @@ public static Packet readObject(ObjectReader r) {
r.end();
return p;
}

public byte[] toBytes() {
ByteArrayObjectWriter writer = Context.newByteArrayObjectWriter("RLPn");
Packet.writeObject(writer, this);
return writer.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public class RelayAggregator {
private final ArrayDB<Address> relayers = Context.newArrayDB("relayers", Address.class);
private final DictDB<Address, Boolean> relayersLookup = Context.newDictDB("relayersLookup", Boolean.class);

private final DictDB<String, Packet> packets = Context.newDictDB("packets", Packet.class);
private final DictDB<String, Boolean> acknowledgedPackets = Context.newDictDB("acknowledgedPackets", Boolean.class);
private final DictDB<byte[], Boolean> acknowledgedPackets = Context.newDictDB("acknowledgedPackets", Boolean.class);
private final DictDB<byte[], Packet> packets = Context.newDictDB("packets", Packet.class);

private final BranchDB<String, DictDB<Address, byte[]>> signatures = Context.newBranchDB("signatures",
private final BranchDB<byte[], DictDB<Address, byte[]>> signatures = Context.newBranchDB("signatures",
byte[].class);

public RelayAggregator(Address _admin) {
if (admin.get() == null) {
admin.set(_admin);
signatureThreshold.set(DEFAULT_SIGNATURE_THRESHOLD);
addRelayer(_admin);
}
}

Expand All @@ -61,12 +60,6 @@ public void setAdmin(Address _admin) {

Context.require(admin.get() != _admin, "admin already set");

// add new admin as relayer
addRelayer(_admin);

// remove old admin from relayer list
removeRelayer(admin.get());

admin.set(_admin);
}

Expand Down Expand Up @@ -108,10 +101,9 @@ public void setRelayers(Address[] newRelayers, int threshold) {
addRelayer(newRelayer);
}

Address adminAdrr = admin.get();
for (int i = 0; i < relayers.size(); i++) {
Address oldRelayer = relayers.get(i);
if (!oldRelayer.equals(adminAdrr) && !newRelayersMap.containsKey(oldRelayer)) {
if (!newRelayersMap.containsKey(oldRelayer)) {
removeRelayer(oldRelayer);
}
}
Expand All @@ -128,8 +120,13 @@ public boolean packetSubmitted(
Address relayer,
String srcNetwork,
String srcContractAddress,
BigInteger srcSn) {
String pktID = Packet.createId(srcNetwork, srcContractAddress, srcSn);
BigInteger srcSn,
BigInteger srcHeight,
String dstNetwork,
String dstContractAddress,
byte[] data) {
Packet pkt = new Packet(srcNetwork, srcContractAddress, srcSn, srcHeight, dstNetwork, dstContractAddress, data);
byte[] pktID = pkt.getId();
byte[] existingSign = signatures.at(pktID).get(relayer);
return existingSign != null;
}
Expand All @@ -138,8 +135,13 @@ public boolean packetSubmitted(
public boolean packetAcknowledged(
String srcNetwork,
String srcContractAddress,
BigInteger srcSn) {
String pktID = Packet.createId(srcNetwork, srcContractAddress, srcSn);
BigInteger srcSn,
BigInteger srcHeight,
String dstNetwork,
String dstContractAddress,
byte[] data) {
Packet pkt = new Packet(srcNetwork, srcContractAddress, srcSn, srcHeight, dstNetwork, dstContractAddress, data);
byte[] pktID = pkt.getId();
return acknowledgedPackets.get(pktID) != null && acknowledgedPackets.get(pktID) == true;
}

Expand All @@ -157,7 +159,7 @@ public void submitPacket(
relayersOnly();

Packet pkt = new Packet(srcNetwork, srcContractAddress, srcSn, srcHeight, dstNetwork, dstContractAddress, data);
String pktID = pkt.getId();
byte[] pktID = pkt.getId();

if (acknowledgedPackets.get(pktID) != null && acknowledgedPackets.get(pktID) == true) {
return;
Expand All @@ -184,7 +186,7 @@ public void submitPacket(
setSignature(pktID, Context.getCaller(), signature);

if (signatureThresholdReached(pktID)) {
byte[][] sigs = getSignatures(srcNetwork, srcContractAddress, srcSn);
byte[][] sigs = getSignatures(pktID);
byte[] encodedSigs = serializeSignatures(sigs);
PacketAcknowledged(
pkt.getSrcNetwork(),
Expand All @@ -200,8 +202,7 @@ public void submitPacket(
}
}

private byte[][] getSignatures(String srcNetwork, String srcContractAddress, BigInteger srcSn) {
String pktID = Packet.createId(srcNetwork, srcContractAddress, srcSn);
private byte[][] getSignatures(byte[] pktID) {
DictDB<Address, byte[]> signDict = signatures.at(pktID);
ArrayList<byte[]> signatureList = new ArrayList<byte[]>();

Expand All @@ -220,7 +221,7 @@ private byte[][] getSignatures(String srcNetwork, String srcContractAddress, Big
return sigs;
}

protected void setSignature(String pktID, Address addr, byte[] sign) {
protected void setSignature(byte[] pktID, Address addr, byte[] sign) {
signatures.at(pktID).set(addr, sign);
}

Expand Down Expand Up @@ -256,7 +257,7 @@ protected static byte[][] deserializeSignatures(byte[] encodedSigs) {
}

private void adminOnly() {
Context.require(Context.getCaller().equals(admin.get()), "Unauthorized: caller is not the leader relayer");
Context.require(Context.getCaller().equals(admin.get()), "Unauthorized: caller is not the admin");
}

private void relayersOnly() {
Expand Down Expand Up @@ -285,7 +286,7 @@ private void removeRelayer(Address oldRelayer) {
}
}

private Boolean signatureThresholdReached(String pktID) {
private Boolean signatureThresholdReached(byte[] pktID) {
int noOfSignatures = 0;
for (int i = 0; i < relayers.size(); i++) {
Address relayer = relayers.get(i);
Expand All @@ -297,7 +298,7 @@ private Boolean signatureThresholdReached(String pktID) {
return noOfSignatures >= signatureThreshold.get();
}

private void removePacket(String pktID) {
private void removePacket(byte[] pktID) {
packets.set(pktID, null);
DictDB<Address, byte[]> signDict = signatures.at(pktID);

Expand Down
Loading

0 comments on commit 61dd932

Please sign in to comment.