Skip to content
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

Persistent mode #347

Closed
3 tasks
Tracked by #349
xlc opened this issue Jul 27, 2023 · 3 comments · Fixed by #392
Closed
3 tasks
Tracked by #349

Persistent mode #347

xlc opened this issue Jul 27, 2023 · 3 comments · Fixed by #392

Comments

@xlc
Copy link
Member

xlc commented Jul 27, 2023

  • Save chain/blocks to sqlite db
  • Load chain from db
  • Config to specify max number of blocks to be stored in memory. If db is enabled, save them to db before purge.
This was referenced Jul 27, 2023
@qiweiii
Copy link
Member

qiweiii commented Jul 31, 2023

  • Config to specify max number of blocks to be stored in memory. (Max memory block count #353)
    • background: problem is now all blocks are in memory, long-running testnet create too many blocks will break the program.
    • stage1: when exceed the max number of block, delete old blocks, so it won't break
      • add a config max-memory-block-count, default to a number, maybe 2000
      • in blockchain/index, blocksByHash object records all the blocks in memory, when #registerBlock, we can check the number of blocks, if exceed the max-memory-block-count, remove the earliest inserted block. Since we need insertion order, maybe change it to a JS Map() to make it a simple LRU data structure.
  • If db is enabled, save chain/blocks to db before purge (Save blocks to db #359)
    • entities:
      •   @Entity()
          export class Block {
            @PrimaryColumn()
            blockHash: string;
          
            @Column()
            blockNumber: number;
          
            @Column({ type: 'json', nullable: true })
            header: object;
          
            @Column({ nullable: true })
            parentBlockHash: string;
          
            @Column('simple-array', { nullable: true })
            extrinsics: string[];
          }
    • when #registerBlock, if exceed max-memory-block-count, save block in db
    • when getBlock, get data from memory first, if not found, get from db
    • when stop, save all blocks in memory to db
  • Load chain/blocks from db, and resume from where it stopped
    • user need to use the same config and the corresponding db file to ensure it works?
    • recreate the blockchain using the config
    • travel to latest block
  • Multiple chain support using different db files

@xlc
Copy link
Member Author

xlc commented Jul 31, 2023

No need to change build block mode. We still want this with all the existing modes.

@qiweiii
Copy link
Member

qiweiii commented Jul 31, 2023

updated

This was referenced Aug 1, 2023
@xlc xlc closed this as completed in #392 Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants