New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read table records after column(struct) update #3825

Closed
psy2848048 opened this Issue Jun 5, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@psy2848048
Copy link

psy2848048 commented Jun 5, 2018

(If table is empty, it doesn't matter.)

Once a or some records has been written into table and table struct is updated, table iterator doesn't work.

It seems the size of one record of "Before" and the iterator of "After" table index is different, and it seems natural in C++ side.
But, in EOS.io world, I think table record migration need to be supported because many struct update would be occurred during dApp development.

The ultimate solution seems to be getting discussed in #354 , so I kindly ask for current and next progress with roughly fixed date.
Or could you please share a workaround?

Thanks in advance!

Before

struct actions_rec {                                                        
    uint64_t       id;                                                      
    time           executed_at;                                             
                                         
    eosio::asset   issued_token;                                            
    uint64_t       issued_point;                                            
                                                                                  
    uint64_t       primary_key()const { return id; };                       
    account_name   get_user() const { return user; };                       
};

After

struct actions_rec {                                                        
    uint64_t       id;                                                      
    time           executed_at;                                             
    eosio::asset   issued_token;                                            
    uint64_t       issued_point;                               
    uint64_t       sentence_id;                                             
                                                                   
    uint64_t       primary_key()const { return id; };                       
    account_name   get_user() const { return user; };                       
};

Member function

void token::getwholeact(uint64_t page){
    auto itr = _action_index.rbegin();
    for (uint64_t i=0; i < 20*(page-1); ++i) itr++;

    eosio::print("[");
    for (uint64_t i=0; i < 20; ++i){
        eosio::print("{");
        eosio::print("    \"time\": ", itr->executed_at);

        eosio::print("  , \"sentence_id\": ", itr->sentence_id);
        eosio::print("  , \"issued_token\": \"", itr->issued_token, "\"");
        eosio::print("  , \"issued_point\": ", itr->issued_point);
        eosio::print("}");

        itr++;

        if (itr == _action_index.rend() ) break;
        if (i != 19) eosio::print(", ");
    }
    eosio::print("]");
}

Symptom

Error 3050003: eosio_assert_message assertion failure
Error Details:
assertion failure with message: read
@heifner

This comment has been minimized.

Copy link
Contributor

heifner commented Jun 5, 2018

Name your new struct actions_rec_v2 and/or rename old to actions_rec_v1 or something similar. Then copy from old to new.

@taokayan

This comment has been minimized.

Copy link
Contributor

taokayan commented Jun 25, 2018

The current release doesn't support dynamic table nor modification of struct member layout. Please consider rename your table name or create different table instead.

@taokayan taokayan closed this Jun 25, 2018

@dominic-healid

This comment has been minimized.

Copy link

dominic-healid commented Jul 11, 2018

@taokayan this is just to clarify your statement above.

Does that mean that if we want to update the smart contract by adding or removing struct properties, that won't work?

@taokayan

This comment has been minimized.

Copy link
Contributor

taokayan commented Jul 11, 2018

Correct. You can make another struct/table and migrate your data from old table to new table.

@dominic-healid

This comment has been minimized.

Copy link

dominic-healid commented Jul 13, 2018

A follow up question: is this also apply when adding new index on the struct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment