Mapping with iterating uint as identifier - multiple transactions in the same blockStruct not being stored in mapping when it contains more than two 'string' properties. Bug?Wrong value returned from functionDeploying a contract multiple times with the same LibraryThis contract does not implement all functions and thus cannot be createdProblems with mapping in soliditySolidity if condition based mapping with multiple structMapping address to multidimensional uintGas cost difference between uint[] and mapping(uint => uint)Multiple Array[] along with mapping handlingremix ERC223: This contract does not implement all functions and thus cannot be created

Fitting a mixture of two normal distributions for a data set?

How many satellites can stay in a Lagrange point?

What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?

Layout of complex table

What do you call the action of someone tackling a stronger person?

How could mana leakage be dangerous to a elf?

What is the line crossing the Pacific Ocean that is shown on maps?

First-year PhD giving a talk among well-established researchers in the field

Averting Real Women Don’t Wear Dresses

C-152 carb heat on before landing in hot weather?

Does image quality of the lens affect "focus and recompose" technique?

How can I set command-line parameters through `.emacs` file?

Does the Paladin's Aura of Protection affect only either her or ONE ally in range?

How to positively portray high and mighty characters?

How to determine what is the correct level of detail when modelling?

Why cruise at 7000' in an A319?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Why is C++ initial allocation so much larger than C's?

Mount a folder with a space on Linux

What would Earth look like at night in medieval times?

Use color ramp to mix materials

Does Hubble need to dump momentum of its reaction wheels?

Why isn’t the tax system continuous rather than bracketed?

What are the penalties for overstaying in USA?



Mapping with iterating uint as identifier - multiple transactions in the same block


Struct not being stored in mapping when it contains more than two 'string' properties. Bug?Wrong value returned from functionDeploying a contract multiple times with the same LibraryThis contract does not implement all functions and thus cannot be createdProblems with mapping in soliditySolidity if condition based mapping with multiple structMapping address to multidimensional uintGas cost difference between uint[] and mapping(uint => uint)Multiple Array[] along with mapping handlingremix ERC223: This contract does not implement all functions and thus cannot be created






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



pragma solidity ^0.5.8;

contract Names

uint lastId;
mapping(uint => string) public numberedNames;

constructor() public
lastId = 0;


function setName(string memory name) public
numberedNames[lastId] = name;
lastId++;




My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










share|improve this question




























    1















    I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



    pragma solidity ^0.5.8;

    contract Names

    uint lastId;
    mapping(uint => string) public numberedNames;

    constructor() public
    lastId = 0;


    function setName(string memory name) public
    numberedNames[lastId] = name;
    lastId++;




    My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










    share|improve this question
























      1












      1








      1








      I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



      pragma solidity ^0.5.8;

      contract Names

      uint lastId;
      mapping(uint => string) public numberedNames;

      constructor() public
      lastId = 0;


      function setName(string memory name) public
      numberedNames[lastId] = name;
      lastId++;




      My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










      share|improve this question














      I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



      pragma solidity ^0.5.8;

      contract Names

      uint lastId;
      mapping(uint => string) public numberedNames;

      constructor() public
      lastId = 0;


      function setName(string memory name) public
      numberedNames[lastId] = name;
      lastId++;




      My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?







      solidity mapping uint256






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 16 at 21:00









      SuperCodeBrahSuperCodeBrah

      1556 bronze badges




      1556 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "642"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f71917%2fmapping-with-iterating-uint-as-identifier-multiple-transactions-in-the-same-bl%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37















          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37













          2












          2








          2







          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer













          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 16 at 21:25









          smarxsmarx

          20.7k1 gold badge8 silver badges20 bronze badges




          20.7k1 gold badge8 silver badges20 bronze badges












          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37

















          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37
















          In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

          – SuperCodeBrah
          Jun 16 at 21:33





          In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

          – SuperCodeBrah
          Jun 16 at 21:33













          Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

          – smarx
          Jun 16 at 21:37





          Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

          – smarx
          Jun 16 at 21:37

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Ethereum Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f71917%2fmapping-with-iterating-uint-as-identifier-multiple-transactions-in-the-same-bl%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Log in Navigation menu

          Invalid response line returned from server: HTTP/2 401 | ErrorPlease Please Help With Error 500 Internal Server Error after upgrading from 1.7 to 1.9Unable to place new customer orders in admin backendMagento - For “Manage Categories” Forbidden You do not have permission to access this documentHTTP ERROR 500 when using require(_once) app/Mage.phpMemcached causing Web Setup Wizard ErrorCould not create an acl object: Invalid XMLAn error occurred on the server. Please try to place the order againInvalid response line returned from server: HTTP/2 200 - message after update to 2.1.7Magento-CE 2.3.0 installation error on XamppMagento 2.2.6- After Migration all default Payment Methods are not working fine