@@ -32,42 +32,58 @@ func (s *Service) HandleTransactionMessage(msg *network.TransactionMessage) (boo
32
32
txs := msg .Extrinsics
33
33
var toPropagate []types.Extrinsic
34
34
35
- rt , err := s .blockState .GetRuntime (nil )
35
+ head , err := s .blockState .BestBlockHeader ()
36
+ if err != nil {
37
+ return false , err
38
+ }
39
+
40
+ hash := head .Hash ()
41
+ rt , err := s .blockState .GetRuntime (& hash )
36
42
if err != nil {
37
43
return false , err
38
44
}
39
45
40
46
for _ , tx := range txs {
41
- ts , err := s .storageState .TrieState (nil )
42
- if err != nil {
43
- return false , err
44
- }
47
+ err = func () error {
48
+ s .storageState .Lock ()
49
+ defer s .storageState .Unlock ()
45
50
46
- rt .SetContextStorage (ts )
51
+ ts , err := s .storageState .TrieState (& head .StateRoot ) //nolint
52
+ if err != nil {
53
+ return err
54
+ }
47
55
48
- // validate each transaction
49
- externalExt := types .Extrinsic (append ([]byte {byte (types .TxnExternal )}, tx ... ))
50
- val , err := rt .ValidateTransaction (externalExt )
51
- if err != nil {
52
- logger .Debug ("failed to validate transaction" , "err" , err )
53
- continue
54
- }
56
+ rt .SetContextStorage (ts )
57
+
58
+ // validate each transaction
59
+ externalExt := types .Extrinsic (append ([]byte {byte (types .TxnExternal )}, tx ... ))
60
+ val , err := rt .ValidateTransaction (externalExt )
61
+ if err != nil {
62
+ logger .Debug ("failed to validate transaction" , "err" , err )
63
+ return nil
64
+ }
65
+
66
+ // create new valid transaction
67
+ vtx := transaction .NewValidTransaction (tx , val )
68
+
69
+ // push to the transaction queue of BABE session
70
+ hash := s .transactionState .AddToPool (vtx )
71
+ logger .Trace ("added transaction to pool" , "hash" , hash )
55
72
56
- // create new valid transaction
57
- vtx := transaction .NewValidTransaction (tx , val )
73
+ // find tx(s) that should propagate
74
+ if val .Propagate {
75
+ toPropagate = append (toPropagate , tx )
76
+ }
58
77
59
- // push to the transaction queue of BABE session
60
- hash := s .transactionState .AddToPool (vtx )
61
- logger .Trace ("Added transaction to queue" , "hash" , hash )
78
+ return nil
79
+ }()
62
80
63
- // find tx(s) that should propagate
64
- if val .Propagate {
65
- toPropagate = append (toPropagate , tx )
81
+ if err != nil {
82
+ return false , err
66
83
}
67
84
}
68
85
69
86
msg .Extrinsics = toPropagate
70
-
71
87
return len (msg .Extrinsics ) > 0 , nil
72
88
}
73
89
0 commit comments