Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Update bounce method #8765

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,11 @@ export abstract class BaseCrossChainUpdateCommand<
status: ccmStatusCode,
sendingChainID: ccm.receivingChainID,
receivingChainID: ccm.sendingChainID,
fee: ccmStatusCode === CCMStatusCode.FAILED_CCM ? BigInt(0) : ccm.fee - minFee,
// The fee of the bounced ccm is set to 0 because it was assigned to the relayer.
fee: BigInt(0),
};

let partnerChainID: Buffer;
const doesReceivingChainExist = await this.stores
.get(ChainAccountStore)
.has(context, bouncedCCM.receivingChainID);

const mainchainID = getMainchainID(bouncedCCM.receivingChainID);
const ownChainAccount = await this.stores.get(OwnChainAccountStore).get(context, EMPTY_BYTES);
Expand All @@ -398,14 +396,18 @@ export abstract class BaseCrossChainUpdateCommand<
// Processing on a sidechain
} else {
// Check for direct channel
partnerChainID = doesReceivingChainExist ? bouncedCCM.receivingChainID : mainchainID;
const receivingChainExists = await this.stores
.get(ChainAccountStore)
.has(context, bouncedCCM.receivingChainID);

partnerChainID = !receivingChainExists ? mainchainID : bouncedCCM.receivingChainID;
}

await this.internalMethod.addToOutbox(context, partnerChainID, bouncedCCM);
const newCCMID = utils.hash(codec.encode(ccmSchema, bouncedCCM));
const newCcmID = utils.hash(codec.encode(ccmSchema, bouncedCCM));
this.events
.get(CcmSendSuccessEvent)
.log(context, bouncedCCM.sendingChainID, bouncedCCM.receivingChainID, newCCMID, {
.log(context, bouncedCCM.sendingChainID, bouncedCCM.receivingChainID, newCcmID, {
ccm: bouncedCCM,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,6 @@ describe('BaseCrossChainUpdateCommand', () => {
describe('bounce', () => {
const ccmStatus = CCMStatusCode.MODULE_NOT_SUPPORTED;
const ccmProcessedEventCode = CCMProcessedCode.MODULE_NOT_SUPPORTED;
// See LIP 45 and getMinReturnFeePerByte implementation for fee calculation breakdown
const expectedFee = BigInt(99000000000);
let stateStore: PrefixedStateReadWriter;

beforeEach(async () => {
Expand Down Expand Up @@ -1092,7 +1090,7 @@ describe('BaseCrossChainUpdateCommand', () => {
status: ccmStatus,
sendingChainID: defaultCCM.receivingChainID,
receivingChainID: defaultCCM.sendingChainID,
fee: expectedFee,
fee: BigInt(0),
},
);
});
Expand Down Expand Up @@ -1128,7 +1126,7 @@ describe('BaseCrossChainUpdateCommand', () => {
status: ccmStatus,
sendingChainID: defaultCCM.receivingChainID,
receivingChainID: defaultCCM.sendingChainID,
fee: expectedFee,
fee: BigInt(0),
},
);
});
Expand Down Expand Up @@ -1158,7 +1156,7 @@ describe('BaseCrossChainUpdateCommand', () => {
status: ccmStatus,
sendingChainID: defaultCCM.receivingChainID,
receivingChainID: defaultCCM.sendingChainID,
fee: expectedFee,
fee: BigInt(0),
},
);
});
Expand Down Expand Up @@ -1199,7 +1197,7 @@ describe('BaseCrossChainUpdateCommand', () => {
status: ccmStatus,
sendingChainID: defaultCCM.receivingChainID,
receivingChainID: defaultCCM.sendingChainID,
fee: expectedFee,
fee: BigInt(0),
},
},
);
Expand Down