These are chat archives for Nethereum/Nethereum

8th
Nov 2018
Tom Ryan
@a7coretryan
Nov 08 2018 01:20
I have a multi-threaded service that would like to post multiple encoded transactions to an Ethereum node. I was reading the Nethereum documentation (https://nethereum.readthedocs.io/en/latest/introduction/web3/) on signing transactions. It states I need to "retrieve the total number of transactions of you sender address". Each of my threads in my service is using the same sender address. I suspect this explanation invalidates what I'm trying to accomplish - meaning that different threads could receive the same Nonce. I have a heavy load of transactions I would like to post and it appears that I have to serialize/single thread this work? I appreciate any clarification.
skosara
@skosara1_twitter
Nov 08 2018 09:34
@juanfranblanco you mean this: "Nethereum sets automatically the GasPrice if not provided by using the clients "GasPrice" call, which provides the average gas price from previous blocks." Cool, I didn't know that, just to double check is this true for all transactions or only contract deployment?
skosara
@skosara1_twitter
Nov 08 2018 09:40
it seems every transaction is 20gwei
skosara
@skosara1_twitter
Nov 08 2018 09:51
so estimation for rinkeby/ropsten is not working as it seems
Juan Blanco
@juanfranblanco
Nov 08 2018 14:32
@a7coretryan if you create a single instance of Web3 it could run in a multithreaded manner.
The account has by default an InMemoryNonceService which keeps a nonce counter for this scenarios
So as long as you use Web3 with a new Account("privateKey") you should be ok
@skosara1_twitter you are referring to the gas price..
the gas price is not related to the estimation of the total gas of a transaction
so your total gas cost will be "total gas" * "gas price"
when you estimate the gas usage of a smart contract it is the "total gas" for that contract transaction
when you retrieve the "gas price" it is the gas price returned by the node, which should the average from the previous blocks
hopefully that makes sense
Tom Ryan
@a7coretryan
Nov 08 2018 16:46
Thanks @juanfranblanco . So are you saying if I use the same Web3 instance across say 10 worker threads using the same sender address that this will work? Or are you saying use the same Account object with different Web3 instances - I think you mean Account? Otherwise it seems a bit odd that Web3 instance data across these threads would be thread safe when issuing the operations within each thread.
Juan Blanco
@juanfranblanco
Nov 08 2018 16:46
both will be the same
but you normally will use the same web3 for simplicity sake
this is a more deep sample / unit test
Tom Ryan
@a7coretryan
Nov 08 2018 16:50
thanks @juanfranblanco - I will take a look. For further clarification I have a Web3 "ConnectionManager" that creates new instances of Web3 that each of the threads use to get a new Web3 instance. It sounds like the Web3 can be a singleton?
Tom Ryan
@a7coretryan
Nov 08 2018 16:59
@juanfranblanco - appears looking at the sample you create and use a single InMemoryNonceService per service executable. If I have my service sharded(multiple service app executables) to handle very heavy transaction loads then these sharded services may have nonce conflicts?
Juan Blanco
@juanfranblanco
Nov 08 2018 17:00
you mean having multiple physical executables
Tom Ryan
@a7coretryan
Nov 08 2018 17:00
yes
Juan Blanco
@juanfranblanco
Nov 08 2018 17:01
yes you may encounter issues
the idea of keeping nonces in memory, is due to the delay that a transaction can get in the transaction queue in the client
so.. if you don't manage this in memory you could create your own custom nonce service which all the executables use
Tom Ryan
@a7coretryan
Nov 08 2018 17:03
yes, makes sense. So I would need to create a singleton service -- yes ok.
Juan Blanco
@juanfranblanco
Nov 08 2018 17:03
yes in no so many words :)
you could use a copy of the inmemoryservice and expose it via a rest api
Tom Ryan
@a7coretryan
Nov 08 2018 17:05
@juanfranblanco -- moving portions of existing system to ethereum and have millions of transactions I'm dealing with. It is already sharded out. Thanks for the clarification and help.
Juan Blanco
@juanfranblanco
Nov 08 2018 17:06
ah excellent :)
although idk if it will make sense to have an account per device for a management perspective
Tom Ryan
@a7coretryan
Nov 08 2018 17:11
yes, interesting thought. There is no reason I have to use a single account -- it just made sense and thats how I built my off-chain config database. Was all good until I hit this snag. I will think about that -- possibly a different account per sharded service.
Tom Ryan
@a7coretryan
Nov 08 2018 23:12
@juanfranblanco I built my own NonceService (copying the inMemoryService) and assigned it to my sender account per the NonceTests samples. I then attempted to call one of my smartcontract functions (which completed successfully) but the GetNextNonceAsync isn't being called. Is there anything I should be aware of to get this to work?