Update a module. If the `db` is not initialized yet (i.e. its program hash is `None`), return an error. Otherwise, if `db.program_hash` matches the given `program_hash`, do nothing and return an empty `UpdateDatabaseResult`. Otherwise, invoke `module.update_database` and return the result.
(
db: &RelationalDB,
module: &ModuleHost,
program: Program,
old_module_info: Arc<ModuleInfo>,
policy: MigrationPolicy,
)
| 843 | /// |
| 844 | /// Otherwise, invoke `module.update_database` and return the result. |
| 845 | async fn update_module( |
| 846 | db: &RelationalDB, |
| 847 | module: &ModuleHost, |
| 848 | program: Program, |
| 849 | old_module_info: Arc<ModuleInfo>, |
| 850 | policy: MigrationPolicy, |
| 851 | ) -> anyhow::Result<UpdateDatabaseResult> { |
| 852 | let addr = db.database_identity(); |
| 853 | match stored_program_hash(db)? { |
| 854 | None => Err(anyhow!("database `{addr}` not yet initialized")), |
| 855 | Some(stored) => { |
| 856 | let res = if stored == program.hash { |
| 857 | info!("database `{}` up to date with program `{}`", addr, program.hash); |
| 858 | UpdateDatabaseResult::NoUpdateNeeded |
| 859 | } else { |
| 860 | info!("updating `{}` from {} to {}", addr, stored, program.hash); |
| 861 | module.update_database(program, old_module_info, policy).await? |
| 862 | }; |
| 863 | |
| 864 | Ok(res) |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /// Encapsulates a database, associated module, and auxiliary state. |
| 870 | struct Host { |
no test coverage detected
searching dependent graphs…