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

feat: market crud #1565

Merged
merged 18 commits into from
Nov 27, 2018
Merged

feat: market crud #1565

merged 18 commits into from
Nov 27, 2018

Conversation

quasisamurai
Copy link
Collaborator

@quasisamurai quasisamurai commented Oct 1, 2018

resolved problem

Here is yet not finished Proof-of-concept CRUD for Market. While I worked on this, i found some critical issues caused by Solidity & EVM design. So let's start:

  • I will describe problem using orders, but it's the same for deals. So when we compare two orders (for ex. in OpenDeal) now we're using this construction. Notice, that Order is a struct.
    Order memory ask = orders[_askID]; Order memory bid = orders[_bidID]
    This one reffers only for 4 variables, named

ask,bid, _askID, _bidID.

But when you're trying to implement CRUD, you need to get exact vars from storage SC.
There are two noticable things aproaching then:

  1. you should use multiple return due solidity currently not supporting struct returning (only in internal functions, that's not applicable for crud)
  2. declare every variable and cast a returned value of getter into concrete type, due contract's functions operate with tuples in case of multiple return.

So data taken from storage contract woul'd be look like this:
( Orders.OrderType orderType, address author, address counterparty, uint duration, uint price, bool[] memory netflags, ProfileRegistry.IdentityLevel identityLevel, address blacklist, bytes32 tag, uint64[] memory benchmarks, uint frozenSum) = ord.GetOrderInfo(askID); Here is the part of order, the immutable data.

This situation totally rapes compiler by calling only a part of one order. Even without casting this vars as a struct But we need two full orders. And that's is only begining.

Why this is going on like this?
Solidity has a limit for local variables (16).

Depending on what you do, you can have around 16 local variables (including parameters and return parameters)

So every input parameter to the function takes one variable, and each return value takes one variable, and each struct cast, and each local declaration takes another variable, and references to storage take two - it surprised me how quickly the limit of 16 was reached.

struct a = struct(b,c,d)

will reserve 5 slots in stack (i'm not sure, it's just an empirical conclusion)
That is an old problem, we faced some months ago and it was a cause why we splitted one order/deal getter by two for both structs.

Since almost each function uses one/two orders or a deal sctruct, there is no way to implement crud this way. That's not the only issue i faced, but I think this is the most significant problem that needs to be solved.

So here is implemented crud for market
Included:

  • Deals

  • Orders

  • ChangeRequests

  • Master-worker contract named Administratum (discussable)

  • Also crud for Administratum

  • Updated event WorkerConfirmed (api-breaking)

  • Updated test enviroment (watch truffle.js & test.sh)

  • Aslo fixed some non-critical bugs

By the way we faced and original problem binded with this EIP. So we decided to modify our stack to avoid problems with contract's bytecode limit.

p.s. some weird comments and getters will be removed after refactoring iteration soon. 🇺🇦

@quasisamurai quasisamurai added T: API breaking This PR/Issue breaks API T: WIP This PR/Issue still in progress P: medium This PR/Issue has normal priority S: Smart-contracts This PR/Issue changes SC T: experiment This PR/Issue is an experiment T: perf This PR/Issue improves performance labels Oct 1, 2018
@quasisamurai quasisamurai requested a review from a team as a code owner October 1, 2018 12:58
@quasisamurai quasisamurai changed the title discuss: market rework feat: market crud Oct 31, 2018
@quasisamurai quasisamurai force-pushed the feat/market-rework branch 2 times, most recently from d7cde6a to b9b5883 Compare November 1, 2018 09:45
await market.RemoveWorker(accounts[0], master, { from: master });
});
});
// describe('RegisterWorker', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for hide this tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due this section tests cases while market is paused. Now master-worker relations is separated contract. Later, me or @abefimov will update tests and may be administratum would be tested in separate test file. And i leaved (just commented, not deleted) this tests for the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep tests clean.
Remove old and write new.
Don't do it like that.

blockchain/source/contracts/Market.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Deals.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Market.sol Outdated Show resolved Hide resolved
@quasisamurai quasisamurai removed the T: WIP This PR/Issue still in progress label Nov 1, 2018
Copy link
Collaborator

@antmat antmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still reviewing

blockchain/source/contracts/Administratum.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Administratum.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Administratum.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Administratum.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/ChangeRequests.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Deals.sol Show resolved Hide resolved
blockchain/source/contracts/Market.sol Outdated Show resolved Hide resolved

uint dealAmount = 0;
Deals dl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use better names here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quasisamurai why? Choose better name pls.

blockchain/source/contracts/Deals.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Administratum.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Administratum.sol Show resolved Hide resolved
blockchain/source/contracts/AdministratumCrud.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Deals.sol Outdated Show resolved Hide resolved
blockchain/source/contracts/Market.sol Show resolved Hide resolved
await market.RemoveWorker(accounts[0], master, { from: master });
});
});
// describe('RegisterWorker', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep tests clean.
Remove old and write new.
Don't do it like that.

blockchain/source/truffle.js Outdated Show resolved Hide resolved
@@ -58,7 +60,7 @@ module.exports = {
},
solc: {
optimizer: {
enabled: true,
enabled: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope :(

@quasisamurai quasisamurai force-pushed the feat/market-rework branch 4 times, most recently from bbc1da5 to 2f0bcb1 Compare November 19, 2018 10:16
@antmat antmat changed the base branch from master to feat/market_v2 November 20, 2018 11:12



//modifiers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "./AdministratumCrud.sol";

contract Administratum is Ownable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Administratable or Ownable


OpenDeal(askID, GetOrdersAmount());
OpenDeal(askID, ordersCrud.GetOrdersAmount());
}

// Deal functions

function OpenDeal(uint _askID, uint _bidID) whenNotPaused public {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public should be first modifier


// if deal is normal
if (ask.duration != 0) {
endTime = startTime.add(bid.duration);
if (ordersCrud.GetOrderDuration(_askID) != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is normal deal is this?
we already have spot and forward deals.

orders crud

master-worker crud

deals crud

change requests crud

massive market reworking

update tests

update migrations

 least crud contracts updations

update gas usage in truffle.js

contracts works fine

migrations updated, will refactor later
@sokel sokel merged commit 514a72c into feat/market_v2 Nov 27, 2018
@sokel sokel deleted the feat/market-rework branch November 27, 2018 16:33
quasisamurai added a commit that referenced this pull request Dec 25, 2018
* administratum: advanced master-worker relations

* feat: change onwable => administratable

* orders crud

* master-worker crud

* deals crud

* change requests crud

* massive market reworking

* feat: migrate func added

* crud for administratum

* fix: cr status bug

* fix: counterpartry bid matching

* fix: migrate order

* rating fields
antmat pushed a commit that referenced this pull request Jan 10, 2019
* administratum: advanced master-worker relations

* feat: change onwable => administratable

* orders crud

* master-worker crud

* deals crud

* change requests crud

* massive market reworking

* feat: migrate func added

* crud for administratum

* fix: cr status bug

* fix: counterpartry bid matching

* fix: migrate order

* rating fields
antmat pushed a commit that referenced this pull request Jan 18, 2019
* administratum: advanced master-worker relations

* feat: change onwable => administratable

* orders crud

* master-worker crud

* deals crud

* change requests crud

* massive market reworking

* feat: migrate func added

* crud for administratum

* fix: cr status bug

* fix: counterpartry bid matching

* fix: migrate order

* rating fields
antmat pushed a commit that referenced this pull request Jan 24, 2019
* administratum: advanced master-worker relations

* feat: change onwable => administratable

* orders crud

* master-worker crud

* deals crud

* change requests crud

* massive market reworking

* feat: migrate func added

* crud for administratum

* fix: cr status bug

* fix: counterpartry bid matching

* fix: migrate order

* rating fields
antmat pushed a commit that referenced this pull request Jan 29, 2019
* administratum: advanced master-worker relations

* feat: change onwable => administratable

* orders crud

* master-worker crud

* deals crud

* change requests crud

* massive market reworking

* feat: migrate func added

* crud for administratum

* fix: cr status bug

* fix: counterpartry bid matching

* fix: migrate order

* rating fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: medium This PR/Issue has normal priority S: Smart-contracts This PR/Issue changes SC T: API breaking This PR/Issue breaks API T: experiment This PR/Issue is an experiment T: perf This PR/Issue improves performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants