[번역] EOS - Developer Log, Stardate 201707.7

in #kr7 years ago (edited)

1.png

이번 주에는 EOS의 아키텍처를 개선하고 개발자 API를 정의하는 데 큰 발전을 이루었습니다. 특히 코드의 사용 용이성과 명확성을 최대화하면서 병렬 처리를 가능하게하는 프로그래밍 모델을 확인했습니다.

업데이트 된 계약 예제

github에서 사람들은 우리가 아키텍처를 테스트하고 원하는 사용예를 적용할 수 있는 많은 예제 계약을 모으기 시작했다는 것을 알 수 있습니다.

단순한 통화 계약은 아래와 같습니다.

/**
 *  Transfer requires that the sender and receiver be the first two
 *  accounts notified and that the sender has provided authorization.
 */
struct Transfer {
  AccountName from;
  AccountName to;
  uint64_t    amount = 0;
  char        memo[]; /// extra bytes are treated as a memo and ignored by logic
};

struct CurrencyAccount {
   CurrencyAccount( uint64_t b = 0 ):balance(b){}

   uint64_t balance = 0;

   /** used as a hint to Db::store to tell it which table name within the current 
    *  scope to use.  Data is stored in tables under a structure like
    *
    *  scope/code/table/key->value
    *
    *  In this case the "singleton" table is designed for constant named keys that
    *  refer to a unique object type. User account balances are stored here:
    *  
    *  username/currency/singleton/account -> CurrencyAccount
    */ 
   static Name tableId() { return NAME("singleton"); }
};


void apply_currency_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   /** will call apply_currency_transfer() method in code defined by transfer.to and transfer.from */
   requireNotice( transfer.to, transfer.from );
   requireAuth( transfer.from );

   static CurrencyAccount from_account;
   static CurrencyAccount to_account;

   Db::get( transfer.from, NAME("account"), from_account );
   Db::get( transfer.to, NAME("account"), to_account );

   assert( from_account.balance >= transfer.amount, "insufficient funds" );
   from_account.balance -= transfer.amount;
   to_account.balance   += transfer.amount;

   if( from_account.balance == 0 )
      Db::remove<CurrencyAccount>( transfer.from, NAME("account") );
   else
      Db::store( transfer.from, NAME("account"), from_account ); 

   Db::store( transfer.to, NAME("account"), to_account ); 
}

이 통화 계약은 몇 가지 주목할만한 측면이 있습니다.

  1. 정상적인 순차 코드처럼 보입니다.
  2. 두 쌍의 사용자간에 병렬로 전송할 수 있습니다

이것은 무엇을 의미 하는가? Alice가 Bob에게 전송하는 동안 Sam은 Jill에게 전송할 수 있음을 의미합니다. 이 통화 계약의 성능은 이전 통화 계약의 단일 스레드 성능 제한에 더 이상 제한되지 않습니다.

계약 체결

우리는 또한 두 가지 다른 통화 계약으로부터 예금과 인출을 하는 간단한 교환 계약을 구현하였습니다:

struct Account {
   uint64_t   a = 0;
   uint64_t   b = 0;
   int        open_orders = 0;

   bool isEmpty()const { return !(a|b|open_orders); }
   /**
    *  Balance records for all exchange users are stored here
    *  exchange/exchange/balance/username -> Balance
    */
   static Name tableId() { return Name("balance"); }
};



/**
 *  This method is called after the "transfer" action of code
 *  "currencya" is called and "exchange" is listed in the notifiers.
 */
void apply_currencya_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   if( transfer.to == "exchange" ) {
      static Balance to_balance;
      Db::get( transfer.from, to_balance );
      to_balance.a += transfer.amount;
      Db::store( transfer.from, to_balance );
   } else if( transfer.from == "exchange" ) {
      requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer

      static Balance to_balance;
      auto balance = Db::get( transfer.to, to_balance );
      assert( balance.a >= transfer.amount, "insufficient funds to withdraw" );
      balance.a -= transfer.amount;

      if( balance.isEmpty() )
         Db::remove<Balance>( transfer.to );
      else
         Db::store( transfer.to, to_balance );
   } else {
      assert( false, "notified on transfer that is not relevant to this exchange" );
   }
}

/**
 *  This method is called after the "transfer" action of code
 *  "currencya" is called and "exchange" is listed in the notifiers.
 */
void apply_currencyb_transfer() {
   const auto& transfer  = currentMessage<Transfer>();

   if( transfer.to == "exchange" ) {
      static Balance to_balance;
      Db::get( transfer.from, to_balance );
      to_balance.b += transfer.amount;
      Db::store( transfer.from, to_balance );
   } else if( transfer.from == "exchange" ) {
      requireAuth( transfer.to ); /// require the reciever of funds (account owner) to authorize this transfer

      static Balance to_balance;
      auto balance = Db::get( transfer.to, to_balance );
      assert( balance.b >= transfer.amount, "insufficient funds to withdraw" );
      balance.b -= transfer.amount;

      if( balance.isEmpty() )
         Db::remove<Balance>( transfer.to );
      else
         Db::store( transfer.to, to_balance );
   } else {
      assert( false, "notified on transfer that is not relevant to this exchange" );
   }
}

이 구현에서 흥미로운 점은 예치 및 인출이 비동기 콜백 또는 기타 복잡한 보류 상태 없이 실행된다는 것입니다. 교환을 요구하는 사용자가 자금을 인출하기 위해 통화 계약을 요청하는 대신, 교환 핸들러(exchange's handler )가 예금과 인출에 호출된다는 통보(caveat)와 함께 모든 사람에게 이전 권한(permission to transfer)을 줍니다. 사용자가 교환 계약에서 그들의 계정보다 많은 금액을 인출하려고 하면 처리기가 전송을 거부합니다.

우리는 아직 입금과 인출 교환 계약의 실제 테스트를 실시하지 않았지만 다음주의 일정에 포함되었습니다. 우리는 또한 우리는 기존의 모든 사용 예를 커버한다는 것을 입증하기 위해 기본적인 소셜 미디어 애플리케이션을 구현할 것입니다.

동기 호출

이번 주 가장 큰 발전 중 하나는 단단히 결합 된 응용 프로그램간에 동시 호출을 허용하면서 동시에 병렬 처리의 이점 대부분을 유지할 수있는 아키텍처입니다. 향후 블로그에서 우리의 메모리와 병렬 실행 구조에 대해 자세히 설명할 것입니다.

저장 비용

어떤 사람들은 EOS 토큰이 미래에 300 억 달러가 되고 스토리지 용량이 1TB 밖에되지 않아서 스토리지 비용이 너무 높을 것이라고 우려했습니다. 나는이 문제를 어떻게 해결하고 토큰 가격과는 독립적으로 스토리지 비용을 유지하는지 설명하는 글을 준비하고 있습니다.

EOS.IO 개발은 큰 진보를 이루고 있습니다!

원문: https://steemit.com/eos/@dan/eos-developer-log-stardate-201707-7

Sort:  

Congratulations @loum! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.24
TRX 0.11
JST 0.029
BTC 69460.45
ETH 3683.07
USDT 1.00
SBD 3.24