이더리움 원본 학습 (5) 거래의 거래 탱크 제출

3351 단어 블록체인
/internet/ethapi/api.go
// submitTransaction is a helper function that submits tx to txPool and logs a message.
func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {
   if err := b.SendTx(ctx, tx); err != nil {
      return common.Hash{}, err
   }
   if tx.To() == nil {
      signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
      from, err := types.Sender(signer, tx)
      if err != nil {
         return common.Hash{}, err
      }
      addr := crypto.CreateAddress(from, tx.Nonce())
      log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
   } else {
      log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
   }
   return tx.Hash(), nil
}

거래 탱크/core/tx_ 먼저 보기pool.go
type TxPool struct {
   config       TxPoolConfig
   chainconfig  *params.ChainConfig
   chain        blockChain
   gasPrice     *big.Int
   txFeed       event.Feed
   scope        event.SubscriptionScope
   chainHeadCh  chan ChainHeadEvent
   chainHeadSub event.Subscription
   signer       types.Signer
   mu           sync.RWMutex

   currentState  *state.StateDB      // Current state in the blockchain head
   pendingState  *state.ManagedState // Pending state tracking virtual nonces
   currentMaxGas uint64              // Current gas limit for transaction caps

   locals  *accountSet // Set of local transaction to exempt from eviction rules
   journal *txJournal  // Journal of local transaction to back up to disk

   //  queue pending 
   pending map[common.Address]*txList   // All currently processable transactions
   queue   map[common.Address]*txList   // Queued but non-processable transactions
   beats   map[common.Address]time.Time // Last heartbeat from each known account
   all     *txLookup                    // All transactions to allow lookups
   priced  *txPricedList                // All transactions sorted by price

   wg sync.WaitGroup // for shutdown sync

   homestead bool
}
// txList is a "list" of transactions belonging to an account, sorted by account
// nonce. The same type can be used both for storing contiguous transactions for
// the executable/pending queue; and for storing gapped transactions for the non-
// executable/future queue, with minor behavioral changes.
type txList struct {
   strict bool         // Whether nonces are strictly continuous or not
   //  nonece 
   txs    *txSortedMap // Heap indexed sorted hash map of the transactions

   costcap *big.Int // Price of the highest costing transaction (reset only if exceeds balance)
   gascap  uint64   // Gas limit of the highest spending transaction (reset only if exceeds block limit)
}
// txSortedMap is a nonce->transaction hash map with a heap based index to allow
// iterating over the contents in a nonce-incrementing way.
type txSortedMap struct {
   //   1.nonce   2.noce gas 
   items map[uint64]*types.Transaction // Hash map storing the transaction data
   index *nonceHeap                    // Heap of nonces of all the stored transactions (non-strict mode)
   cache types.Transactions            // Cache of the transactions already sorted
}

좋은 웹페이지 즐겨찾기