Skip to content

Commit

Permalink
R4R: enable or disable channel through governance (#29)
Browse files Browse the repository at this point in the history
* enable and disable channel through governance

* fix a bug in batch oracle
  • Loading branch information
HaoyangLiu committed Jul 3, 2020
1 parent 7b2906a commit 978d90d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
24 changes: 22 additions & 2 deletions contracts/CrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
event unexpectedRevertInPackageHandler(address indexed contractAddr, string reason);
event unexpectedFailureAssertionInPackageHandler(address indexed contractAddr, bytes lowLevelData);
event paramChange(string key, bytes value);
event enableOrDisableChannel(uint8 indexed channelId, bool isEnable);
event addChannel(uint8 indexed channelId, address indexed contractAddr);

modifier sequenceInOrder(uint64 _sequence, uint8 _channelID) {
Expand Down Expand Up @@ -243,9 +244,9 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
previousTxHeight=block.number;
} else {
txCounter++;
if (txCounter>=batchSizeForOracle) {
if (txCounter>batchSizeForOracle) {
oracleSequence++;
txCounter = 0;
txCounter = 1;
}
}
emit crossChainPackage(bscChainID, uint64(oracleSequence), packageSequence, channelId, payload);
Expand Down Expand Up @@ -287,6 +288,25 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
registeredContractMap[handlerContract] = true;
isRelayRewardFromSystemReward[channelId] = (isRewardFromSystem == 0x0);
emit addChannel(channelId, handlerContract);
} else if (Memory.compareStrings(key, "enableOrDisableChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 2, "length of value for enableOrDisableChannel should be 2, channelId:isEnable");

uint8 channelId;
assembly {
channelId := mload(add(valueLocal, 1))
}
uint8 status;
assembly {
status := mload(add(valueLocal, 2))
}
bool isEnable = (status == 1);

address handlerContract = channelHandlerContractMap[channelId];
if (handlerContract != address(0x00)) { //channel existing
registeredContractMap[handlerContract] = isEnable;
emit enableOrDisableChannel(channelId, isEnable);
}
} else {
require(false, "unknown param");
}
Expand Down
24 changes: 22 additions & 2 deletions contracts/CrossChain.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
event unexpectedRevertInPackageHandler(address indexed contractAddr, string reason);
event unexpectedFailureAssertionInPackageHandler(address indexed contractAddr, bytes lowLevelData);
event paramChange(string key, bytes value);
event enableOrDisableChannel(uint8 indexed channelId, bool isEnable);
event addChannel(uint8 indexed channelId, address indexed contractAddr);

modifier sequenceInOrder(uint64 _sequence, uint8 _channelID) {
Expand Down Expand Up @@ -244,9 +245,9 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
previousTxHeight=block.number;
} else {
txCounter++;
if (txCounter>=batchSizeForOracle) {
if (txCounter>batchSizeForOracle) {
oracleSequence++;
txCounter = 0;
txCounter = 1;
}
}
emit crossChainPackage(bscChainID, uint64(oracleSequence), packageSequence, channelId, payload);
Expand Down Expand Up @@ -288,6 +289,25 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
registeredContractMap[handlerContract] = true;
isRelayRewardFromSystemReward[channelId] = (isRewardFromSystem == 0x0);
emit addChannel(channelId, handlerContract);
} else if (Memory.compareStrings(key, "enableOrDisableChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 2, "length of value for enableOrDisableChannel should be 2, channelId:isEnable");

uint8 channelId;
assembly {
channelId := mload(add(valueLocal, 1))
}
uint8 status;
assembly {
status := mload(add(valueLocal, 2))
}
bool isEnable = (status == 1);

address handlerContract = channelHandlerContractMap[channelId];
if (handlerContract != address(0x00)) { //channel existing
registeredContractMap[handlerContract] = isEnable;
emit enableOrDisableChannel(channelId, isEnable);
}
} else {
require(false, "unknown param");
}
Expand Down
Loading

0 comments on commit 978d90d

Please sign in to comment.