@@ -13,7 +13,6 @@ import (
1313 flowGo "github.com/onflow/flow-go/model/flow"
1414 "github.com/rs/zerolog"
1515 "github.com/sethvargo/go-retry"
16- "golang.org/x/sync/errgroup"
1716
1817 "github.com/onflow/flow-evm-gateway/config"
1918 "github.com/onflow/flow-evm-gateway/metrics"
@@ -93,15 +92,15 @@ func (t *SingleTxPool) Add(
9392 return err
9493 }
9594
96- latestBlock , account , err := t .fetchFlowLatestBlockAndCOA (ctx )
95+ latestBlock , err := t .client . GetLatestBlock (ctx , true )
9796 if err != nil {
9897 return err
9998 }
10099
101100 script := replaceAddresses (runTxScript , t .config .FlowNetworkID )
102101 flowTx , err := t .buildTransaction (
102+ ctx ,
103103 latestBlock ,
104- account ,
105104 script ,
106105 cadence .NewArray ([]cadence.Value {hexEncodedTx }),
107106 coinbaseAddress ,
@@ -157,8 +156,8 @@ func (t *SingleTxPool) Add(
157156// buildTransaction creates a Cadence transaction from the provided script,
158157// with the given arguments and signs it with the configured COA account.
159158func (t * SingleTxPool ) buildTransaction (
159+ ctx context.Context ,
160160 latestBlock * flow.Block ,
161- account * flow.Account ,
162161 script []byte ,
163162 args ... cadence.Value ,
164163) (* flow.Transaction , error ) {
@@ -187,43 +186,19 @@ func (t *SingleTxPool) buildTransaction(
187186 return nil , err
188187 }
189188
190- if err := accKey .SetProposerPayerAndSign (flowTx , account ); err != nil {
189+ coaAddress := t .config .COAAddress
190+ accountKey , err := t .client .GetAccountKeyAtLatestBlock (ctx , coaAddress , accKey .Index )
191+ if err != nil {
192+ return nil , err
193+ }
194+
195+ if err := accKey .SetProposerPayerAndSign (flowTx , coaAddress , accountKey ); err != nil {
191196 accKey .Done ()
192197 return nil , err
193198 }
194199
195200 // now that the transaction is prepared, store the transaction's metadata
196201 accKey .SetLockMetadata (flowTx .ID (), latestBlock .Height )
197202
198- t .collector .OperatorBalance (account )
199-
200203 return flowTx , nil
201204}
202-
203- func (t * SingleTxPool ) fetchFlowLatestBlockAndCOA (ctx context.Context ) (
204- * flow.Block ,
205- * flow.Account ,
206- error ,
207- ) {
208- var (
209- g = errgroup.Group {}
210- err1 , err2 error
211- latestBlock * flow.Block
212- account * flow.Account
213- )
214-
215- // execute concurrently so we can speed up all the information we need for tx
216- g .Go (func () error {
217- latestBlock , err1 = t .client .GetLatestBlock (ctx , true )
218- return err1
219- })
220- g .Go (func () error {
221- account , err2 = t .client .GetAccount (ctx , t .config .COAAddress )
222- return err2
223- })
224- if err := g .Wait (); err != nil {
225- return nil , nil , err
226- }
227-
228- return latestBlock , account , nil
229- }
0 commit comments