Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Nov 10, 2022
1 parent 800a85a commit e5c675e
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 369 deletions.
24 changes: 17 additions & 7 deletions dot/core/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@ func (s *Service) validateTransaction(head *types.Header, rt RuntimeInstance,
s.storageState.Lock()

ts, err := s.storageState.TrieState(&head.StateRoot)
s.storageState.Unlock()
if err != nil {
return nil, fmt.Errorf("cannot get trie state from storage for root %s: %w", head.StateRoot, err)
s.storageState.Unlock()
return nil, fmt.Errorf("getting trie state from storage: %w", err)
}

rt.SetContextStorage(ts)
// ValidateTransaction modifies the trie state so we want to snapshot it
// so that the original trie state remains unaffected.
temporaryState := ts.Snapshot()

s.storageState.Unlock()

// validate each transaction
externalExt, err := s.buildExternalTransaction(rt, tx)
if err != nil {
return nil, fmt.Errorf("building external transaction: %w", err)
}

rt.SetContextStorage(temporaryState)

validity, err = rt.ValidateTransaction(externalExt)

// Clear the reference to the snapshoted trie state so it can get garbage collected.
rt.SetContextStorage(nil)

if err != nil {
logger.Debugf("failed to validate transaction: %s", err)
return nil, err
Expand All @@ -50,8 +60,8 @@ func (s *Service) validateTransaction(head *types.Header, rt RuntimeInstance,

// HandleTransactionMessage validates each transaction in the message and
// adds valid transactions to the transaction queue of the BABE session
// returns boolean for transaction propagation, true - transactions should be propagated
func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.TransactionMessage) (bool, error) {
func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.TransactionMessage) (
propagateTransactions bool, err error) {
logger.Debug("received TransactionMessage")

if !s.net.IsSynced() {
Expand All @@ -65,13 +75,13 @@ func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.Transact

head, err := s.blockState.BestBlockHeader()
if err != nil {
return false, err
return false, fmt.Errorf("getting best block header: %w", err)
}

bestBlockHash := head.Hash()
rt, err := s.blockState.GetRuntime(bestBlockHash)
if err != nil {
return false, err
return false, fmt.Errorf("getting runtime from block state: %w", err)
}

allTxnsAreValid := true
Expand Down
Loading

0 comments on commit e5c675e

Please sign in to comment.