OpenST / mosaic-contracts

Mosaic-0: Gateways and anchors on top of Ethereum to scale DApps
https://discuss.openst.org/c/mosaic
MIT License
114 stars 31 forks source link

Stop storing StakeRequest object in OSTComposer contract's storage #770

Closed pgev closed 5 years ago

pgev commented 5 years ago

Storing StakeRequest objects in contract's storage are very expensive. Instead, we can change interfaces of the following external functions: acceptStakeRequest(), revokeStakeRequest() and rejectStakeRequest(), to pass all needed params to calculate hash of a StakeRequest.

benjaminbollen commented 5 years ago

mapping(bytes32 => bool) public stakeRequests

abhayks1 commented 5 years ago

Gas Analysis keeping StakeRequests object storage

abhayks1 commented 5 years ago

Gas Analysis after removing StakeRequests storage

benjaminbollen commented 5 years ago

@abhayks1 the large amount of gas consumed in requestStake is for the deployment of the StakerProxy contract. Can you run the numbers when the same staker does a second stake request; then the contract already exists.

We'll need to update the StakerProxy to a proxy contract in the other sense, to further bring down the gas cost in another ticket.

abhayks1 commented 5 years ago
{ tx: '0xa16faade7b93dd88a9de6f7bd13d58bf2b56b55b1fea9ecf7642a302975bb166',
  receipt: 
   { transactionHash: '0xa16faade7b93dd88a9de6f7bd13d58bf2b56b55b1fea9ecf7642a302975bb166',
     transactionIndex: 0,
     blockHash: '0x21ccab52abb2adb6144f4ea9ea36688ed5527219233c4022e0955dabd508a804',
     blockNumber: 102,
     from: '0xda3bbd42ba0a16be50ff2963947e03d7bab26291',
     to: '0x126c59d4747852ca6ae3a5100cff930684b76f62',
     gasUsed: 149411,
     cumulativeGasUsed: 149411,
     contractAddress: null,
     logs: [ [Object] ],
     status: true,
     logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000001000000000000010000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000210000000000200000',
     v: '0x1c',
     r: '0x48018481bc1ca08a8d0021f47f2e5e5b2c906b0f5cc590674ed7517645a16735',
     s: '0x4f4d5c27f8aca651e2c2f9daa957a59657234a27e1322077986966ac561a119c',
     rawLogs: [ [Object] ] },
  logs: 
   [ { logIndex: 0,
       transactionIndex: 0,
       transactionHash: '0xa16faade7b93dd88a9de6f7bd13d58bf2b56b55b1fea9ecf7642a302975bb166',
       blockHash: '0x21ccab52abb2adb6144f4ea9ea36688ed5527219233c4022e0955dabd508a804',
       blockNumber: 102,
       address: '0x126C59D4747852Ca6aE3A5100cff930684b76F62',
       type: 'mined',
       id: 'log_44531c81',
       event: 'StakeRequested',
       args: [Object] } ] }

cc: @benjaminbollen