message: Move account module check out of module creation
diff: @@ -76,20 +76,23 @@ namespace eosio { namespace chain {
  }
  it = instantiation_cache.emplace(code_id, runtime_interface->instantiate_module((const char*)bytes.data(), bytes.size(), parse_initial_memory(module))).first;
  + }
  auto it_account_module = account_module_map.find(account);
  digest_type old_digest;
  - bool found = false;
  + bool oldcode_replaced = false;
  if (it_account_module != account_module_map.end()) {
  if (code_id != it_account_module->second.digest) {
  old_digest = it_account_module->second.digest;
  - found = true;
  - }
  + account_module_map[account] = {code_id, it->second};
  + oldcode_replaced = true;
  }
  -
  + } else {
  account_module_map[account] = {code_id, it->second};
  + }
  - if (found) {
  + //check code reference
  + if (oldcode_replaced) {
  auto _it = instantiation_cache.find(old_digest);
  if (_it != instantiation_cache.end()) {
  //no account reference to this instantiated module anymore, release it
  @@ -98,7 +101,7 @@ namespace eosio { namespace chain {
  }
  }
  }
  - }
  +
  return it->second;
  }
  